-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patheuler-criterion.txt
More file actions
45 lines (41 loc) · 1.06 KB
/
Copy patheuler-criterion.txt
File metadata and controls
45 lines (41 loc) · 1.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
//Your friend gives you an equation A≡X2(modM)A≡X2(modM) and asks you to find an integer solution for XX.
//However, you know your friend's mischievous nature and suspect that there is no solution to such an equation.
//Thus, you first want to find out whether there is a solution to it.
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
long powmod(long x,long e,long mod)
{
long res;
if(e==0)
res=1;
else if(e==1)
res=x;
else
{
res=powmod(x,e/2,mod);
res=res*res%mod;
if(e%2)
res=res*x%mod;
}
return res;
}
int main() {
/* Enter your code here. Read input from STDIN. Print output to STDOUT */ long t;
scanf("%ld",&t);
while(t--)
{
long a,m;
scanf("%ld%ld",&a,&m);
if(a==0)
{printf("YES\n");continue;}
if(m==2)
{printf("YES\n");continue;}
if(powmod(a,(m-1)/2,m)==1)
printf("YES\n");
else
printf("NO\n");
}
return 0;
}