51nod 2级算法题-1014

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

考虑P的范围就直接暴力枚举了

#include <iostream>
#include <cstring>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <queue>
#include <stack>
using namespace std;
#define endl "\n"
const long long maxn=1e6+100;
int main(){
    ios::sync_with_stdio(false);
    long long p,x;
    cin>>p>>x;
    int flag=0;
    for(long long  i=0;i<p;i++){
        if(flag && (i*i)%p==x){
            cout<<" "<<i;
        }
        if(!flag && (i*i)%p==x){
            cout<<i;
            flag=1;
        }
    }
    if(!flag){
        cout<<"No Solution";
    }
    cout<<endl;
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值