您的位置:首页 > 编程语言 > C语言/C++

Contest 2016-5-7 A(HDU 5615)

2016-05-07 19:31 162 查看
#include<cstdio>
#include<cmath>

int a,b,c;
int p[20000],cnt1,k[20000],cnt2;

bool f(){
int i,j;
cnt1=cnt2=0;
int sqrt1=(int)sqrt(a);
for(i=1;i<=sqrt1;++i){
if(a%i==0){
p[cnt1++]=i;
p[cnt1++]=a/i;
}
}
int sqrt2=(int)sqrt(c);
for(i=1;i<=sqrt2;++i){
if(c%i==0){
k[cnt2++]=i;
k[cnt2++]=c/i;
}
}
int q,m;
for(i=0;i<cnt1;++i){
for(j=0;j<cnt2;++j){
q=a/p[i];
m=c/k[j];
if(q*k[j]+m*p[i]==b){
return true;
}
}
}
return false;
}

int main(){
int T;
scanf("%d",&T);
while(T--){
scanf("%d%d%d",&a,&b,&c);
if(f())
printf("YES\n");
else
printf("NO\n");
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  C++