X^2 Mod P

来源:互联网 发布:js正则匹配网址 编辑:程序博客网 时间:2024/04/25 15:18
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

#include <iostream>#include <cstring>using namespace std;typedef long long int ll;int main(){ll P, A;cin >> P >> A;bool found = false;for (ll i = 0; i <= P; i++){if ((i * i) % P == A){cout << i << " ";found = true;}}if (!found){cout << "No Solution";}cout << endl;   return 0;}