app开发者平台在数字化时代的重要性与发展趋势解析
600
2022-10-09
372. Super Pow
Your task is to calculate ab mod 1337 where a is a positive integer and b is an extremely large positive integer given in the form of an array.
Example1:
a = 2b
Example2:
a = 2b
class Solution { public int superPow(int a, int[] b) { int result = 1; for (int i = 0; i < b.length; i++){ result = (helper(result,10) * helper(a, b[i])) % 1337; // It's the key } return result; } private int helper(int a, int b){ // Function to get the value of (a^b)mod(1337) int result; if (b == 0) return 1; if (b == 1) return a % 1337; return (helper(a, b/2) * helper(a, b - b/2)) % 1337; }}
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。
发表评论
暂时没有评论,来抢沙发吧~