Problem Description
1 #include<stdio.h> 2 #include<string.h> 3 #include<stdlib.h> 4 #include<queue> 5 #include<stack> 6 #include<math.h> 7 #include<vector> 8 #include<map> 9 #include<set> 10 #include<stdlib.h> 11 #include<cmath> 12 #include<string> 13 #include<algorithm> 14 #include<iostream> 15 #define exp 1e-10 16 17 using namespace std; 18 19 __int64 Quick_Mod(int a, int b, int m) 20 { 21 __int64 res = 1,term = a % m; 22 while(b) 23 { 24 if(b & 1) res = (res * term) % m; 25 term = (term * term) % m; 26 b >>= 1; 27 } 28 return res%m; 29 } 30 31 int main() 32 { 33 int c,k1,b1,k2,t; 34 int f; 35 t=1; 36 while(cin>>c>>k1>>b1>>k2) 37 { 38 cout<<"Case #"<<t++<<":"<<endl; 39 f=0; 40 int a,b,x,y; 41 for(a=1;a<c;++a) 42 { 43 x=Quick_Mod(a,k1,c); 44 b=c-Quick_Mod(a,k1+b1,c); 45 y=Quick_Mod(b,k2,c); 46 if(x==y) 47 { 48 f=1; 49 cout<<a<<" "<<b<<endl; 50 } 51 } 52 if(f==0) 53 { 54 cout<<-1<<endl; 55 } 56 57 } 58 59 return 0; 60 }
原文:http://www.cnblogs.com/Traveller-Leon/p/4841998.html