#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
*/
#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
*/
沒有留言:
張貼留言