给出两个数 A B, 那么s=gcd(A.B)则是 A ,B中公共同源数的最大集合,
那么 a= A/s b=B/s ;
只要证明 a ,b 和 s 同源就好。
那么 求 gcd(a(b),s ) 最后就能得出是否是同源。
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int maxn=111;
ll gcd(ll a,ll b){
if(b==0) return a;
return gcd(b,a%b);
}
bool fun(ll a,ll b){
ll t=gcd(a,b);//printf("%d \n",a);
if(t==1){
if(a==1) return true;
else return false;
}
fun(a/t,b);
}
int main(){
ll x,y;
while(~scanf("%lld %lld",&x,&y)){
ll s=gcd(x,y);
if(s==1) {printf("No\n");continue;}
x/=s;y/=s;
if(fun(x,s)&&fun(y,s)) printf("Yes\n");
else printf("No\n");
}
return 0;
}