1014 X^2 Mod P

X*X mod P = A,其中P为质数。给出P和A,求<=P的所有X。
Input
两个数P A,中间用空格隔开。(1 <= A < P <= 1000000, P为质数)
Output
输出符合条件的X,且0 <= X <= P,如果有多个,按照升序排列,中间用空格隔开。
如果没有符合条件的X,输出:No Solution
Input示例
13 3
Output示例
4 9

#include <iostream>  
#define ll long long
using namespace std;  
int s[1000010];
int main() {  
	int a, p, cnt;
	cnt = 0;
	cin>>a>>p;
	for(int i = 1; i <= a; i++) {
		ll t = i*i;
		if(t%a==p) {
			s[cnt++] = i;
		}
	}
	if(cnt==0) {
		cout<<"No Solution"<<endl;
	} else {
		for(int i = 0; i < cnt-1; i++) {
			if(s[i]) {
				cout<<s[i]<<" ";
			}
		}
		cout<<s[cnt-1]<<endl;	
	}
	return 0;  
}  

猜你喜欢

转载自blog.csdn.net/adusts/article/details/80709760