标签:mit 测试数据 amp return clu ble result 表示 nyoj
求a的b次方对c取余的值
3 2 3 5 3 100 10 11 12345 12345
3 1 10481
公式求幂→二分求幂→快速求幂→快速求幂取模
1 2 #include <iostream> 3 using namespace std; 4 long long pow(long long a,long long n,long long b){ 5 long long result=1; 6 while(n>0){ 7 if(n&1) 8 result=result*a%b; 9 n>>=1; 10 a=a*a%b; 11 } 12 return result; 13 } 14 int main(void) 15 { 16 int cases; 17 long long a,n,b; 18 cin >> cases; 19 while(cases--){ 20 cin >> a >> n >> b; 21 cout << pow(a,n,b)<<endl; 22 } 23 return 0; 24 }
标签:mit 测试数据 amp return clu ble result 表示 nyoj
原文地址:http://www.cnblogs.com/ray-coding-in-rays/p/6290508.html