2013年11月11日 星期一

5 的 100次方 mod 7

#include <iostream>
#include <map>
using namespace std;
int main(){
map<
int,bool> m; //記錄已經出現的餘數
int a,b,c,d;
cin >> a >> b>>c;
d = a;
while(!m[d]){
m[d]=
true;
d=(d*a)%b;
}
//cout << m.size();
c = c%m.size();
d = a;
for(int i=0;i<c-1;i++){
d=(d*a)%b;
}
cout<<d;

system(
"pause");
return 0;
}
/*
5 7 1 => 5
5 7 100 => 2
*/

沒有留言:

張貼留言