|  | 
|  | 
| back to board | I get accept,but i don't why Posted by aurora  5 Sep 2016 18:18#include<iostream>using namespace std;
 int main()
 {
 int N, M, Y;
 while (cin >> N >> M >> Y)
 {
 int f = 0,t=-1;
 for (int i = 0; i < M; i++)
 {
 int x = i;
 long long y = x;
 for (int j = 2; j < N + 1; j++)
 {
 y *= x;
 y %= M;
 }
 if (y== Y)
 {
 if (f > 0)
 cout << ' ';
 cout << x ;
 f ++;
 }
 }
 if (f == 0)
 cout << t;
 cout << endl;
 }
 return 0;
 }
 
 why it can get accept,but this one get WA
 
 #include<iostream>
 using namespace std;
 int main()
 {
 int N, M, Y;
 while (cin >> N >> M >> Y)
 {
 int f = 0,t=-1;
 for (int i = 0; i < M; i++)
 {
 int x = i;
 long long y = x;
 for (int j = 2; j < N + 1; j++)
 {
 y *= x;
 }
 if (y%M== Y)
 {
 if (f > 0)
 cout << ' ';
 cout << x ;
 f ++;
 }
 }
 if (f == 0)
 cout << t;
 cout << endl;
 }
 return 0;
 }
Re: I get accept,but i don't why Your second program assumes that all x^N are less than long long limit.It isn't true. 10^999 requires about 999 digits. long long limit is about 19 digits.
 | 
 | 
|