51Nod 1014 X^2 Mod P

注意潜在范围 x*x用long long

#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
#define rep(i,a,n) for(int i = a; i < n; i++)
#define repe(i,a,n) for(int i = a; i <= n; i++)
#define per(i,n,a) for(int i = n; i >= a; i--)
#define clc(a,b) memset(a,b,sizeof(a))
#define INF 1e18+100
#define N 1000010
typedef long long LL;
int arr[N];
int main()
{
    int a,p;
    while(~scanf("%d%d",&p,&a)){
        int cnt=0;
        for(int i=0;i<=p;i++){
            if((LL)i*i%p==a){
                arr[cnt++]=i;
            }
        }
        if(cnt==0){
            puts("No Solution");
            continue;
        }
        sort(arr,arr+cnt);
        printf("%d",arr[0]);
        for(int i=1;i<cnt;i++){
            printf(" %d",arr[i]);
        }
        puts("");
    }
    return 0;
}
原文地址:https://www.cnblogs.com/kimsimple/p/7463919.html