标签:二进制 using std iostream numbers 快速 style 注意 main
【题目链接】
http://poj.org/problem?id=1995
【算法】
1 #include <iostream> 2 using namespace std; 3 int z,m,h,cur,ans,a,b; 4 void calc() 5 { 6 cin>>a>>b; 7 cur = 1 % m; 8 for(; b; b >>= 1) { 9 if(b & 1) cur = (long long)cur * a % m; 10 a = (long long)a * a % m; 11 } 12 ans = (long long)(ans+cur) % m; 13 } 14 int main() 15 { 16 cin>>z; 17 while(z--) 18 { 19 ans = 0; 20 cin>>m>>h; 21 while(h--) calc(); 22 cout << ans%m << endl; 23 } 24 }
poj_1995 Raising Modulo Numbers (快速幂)
标签:二进制 using std iostream numbers 快速 style 注意 main
原文地址:https://www.cnblogs.com/Willendless/p/9309225.html