Super Pow

xiaoxiao2021-02-28  96

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 = 2 b = [3] Result: 8

Example2:

a = 2 b = [1,0] Result: 1024 解析:

每一位一位的的求,当前位为之前所有位的结果的10次方再乘以a的当前位次方。

代码:

class Solution { public: int spow(int a,int b) { int base=1337; a%=1337; int res=1; for (int i=0; i<b; i++) { res*=a; res%=base; } return res; } int superPow(int a, vector<int>& b) { int ans=1; int base=1337; for (int i=0; i<b.size(); i++) { ans=(spow(ans,10)*spow(a,b[i]))
转载请注明原文地址: https://www.6miu.com/read-39625.html

最新回复(0)