您的位置:首页 > 其它

51Nod--1014 X^2 Mod P

2017-06-13 00:39 225 查看
题目链接:http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1014

基准时间限制:1 秒 空间限制:131072 KB

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

采用直接枚举就行了,因为其时间复杂度是百万级的,1秒可以过:

#include <iostream>
#include <cmath>
using namespace std;
const long long N = 1000010;

int main() {
int count = 0;
int p, a;
cin >> p >> a;
for(long long i = 1; i <= p; i++) {
if(i*i % p == a) {
if(count++) {
cout << " ";
}
cout << i;
}
}
if(count == 0) {
cout << "No Solution";
}

return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: