372. Super Pow

网友投稿 562 2022-10-09

372. Super Pow

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小时内删除侵权内容。

上一篇:Oqtane是Blazor的模块化应用程序框架
下一篇:Onsen UI - HTML5混合移动应用程序框架(onsensou是什么牌子)
相关文章

 发表评论

暂时没有评论,来抢沙发吧~