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
Sample Input
13 3
Sample Output
4 9
解题剖析:
很简单的一道水题,但要注意定义和题干要求里的一些细节。
My code:
#include <bits/stdc++.h>
using namespace std;
#define ll long long //注意ll的定义
int n,q[1000005];
int main()
{
ll p,a;
scanf("%lld%lld",&p,&a);
for(int i=0;i<=p;i++) //注意题干要求
if((ll)i*i%p==a)
q[++n]=i;
if(!n)
puts("No Solution");
else
{
for(int i=1;i<n;i++)
printf("%d ",q[i]); //只有数值之间有空格
printf("%d\n",q[n]);
}
return 0;
}