题目链接:https://www.51nod.com/onlineJudge/questionCode.html#!problemId=1014
题目:
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
直接暴力做。
#include <iostream>
#include<bits/stdc++.h>
#define LL long long
using namespace std;
int d[1100000];
int main()
{
LL p,a;
int m=0;
scanf("%lld%lld",&p,&a);
for(int i=0;i<=p;i++)
if((LL)i*i%p==a) d[m++]=i;
if(m==0) cout<<"No Solution"<<endl;
else
{
for(int i=0;i<m;i++)
{
if(i!=0) cout<<" ";
cout<<d[i];
}
cout<<endl;
}
}