Description
给出两个正整数A和B
请输出A的B次幂
结果可能很大,请对1000000007求模
Input
A和B,两个整数均不大于10^18
Output
A的B次幂对1000000007求模
Sample Input 1
2 2
Sample Output 1
4
Sample Input 2
2 10
Sample Output 2
1024
快速幂:其实我也没搞明白。emmmmmmm等我搞明白了再说吧。献上代码!
1 #include<iostream> 2 using namespace std; 3 long long cu(long long a, long long b) { 4 long long s = 1; 5 while(b > 0) { 6 if(b%2 == 1) { 7 s = s % 1000000007; 8 a = a % 1000000007; 9 s = s * a; 10 } 11 a = a % 1000000007; 12 a = a * a; 13 b = b / 2; 14 } 15 return s % 1000000007; 16 } 17 int main() 18 { 19 long long a, b; 20 cin >> a >> b; 21 cout << cu(a, b); 22 }