您的位置:首页 > 其它

【51Nod】1014 X^2 Mod P

2017-05-23 19:19 281 查看

题意

X*X mod P = A,其中P为质数。给出P和A,求<=P的所有X。

解题思路

从0~P枚举X,把满足条件的X输出。

参考代码

#include <iostream>
using namespace std;
typedef long long ll;
int main(){
ll p,a;
while (cin>>p>>a){
int cnt=0;
for (ll i=2;i<=p;i++){
if (i*i%p==a){
if (cnt==0) cout<<i;
else cout<<" "<<i;
cnt++;
}
}
if (cnt==0) cout<<"No Solution";
cout<<endl;
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: