-
Notifications
You must be signed in to change notification settings - Fork 0
/
ecnuoj2955.cpp
67 lines (66 loc) · 1.12 KB
/
ecnuoj2955.cpp
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#include<iostream>
#include<cmath>
#include<algorithm>
using namespace std;
int gcd(int m,int n)
{
int a=max(m,n);
int b=min(m,n);
int res=b;
while (b!=0)
{
res=a%b;
a=b;
b=res;
}
return a;
}
bool isprime(int n)
{
if(n<2)
{
return false;
}
for(size_t i=2;i*i<n;i++)
{
if(n%i==0)
{
return false;
}
}
return true;
}
int main()
{
int T=0;
scanf("%d",&T);
int countT=0;
while(T>0)
{
int a=0;
int b=0;
scanf("%d %d",&a,&b);
cout<<"case #"<<countT<<":"<<endl;
if(gcd(a,b)==1)
{
cout<<"No"<<endl;
}
else
{
int j=0;
int res=0;
for(j=2;j<=gcd(a,b);j++)
{
if(isprime(j)&&gcd(a,b)%j==0)
{
res=j;
break;
}
}
cout<<"Yes"<<" "<<res<<endl;
}
T--;
countT++;
}
return 0;
}