题目链接: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;
}
}

本文介绍了一道编程题的解决方法,题目要求找出所有符合条件的X,使得X*X mod P = A,其中P为质数。通过暴力枚举的方式进行解答,并给出了完整的C++代码实现。

812

被折叠的 条评论
为什么被折叠?



