乍一看数据那么大,推出了(q+m)(p+k)=a+b+c;想着只要a+b+c不是质数就好了,就傻傻的打了个3亿的质数表,差点把我电脑运行爆,弄到一半赶紧关了,肯定超时了,看了别人的才知道自己想复杂了,不用那么麻烦的,暴力下判断就好了;由于(px+k)*(qx+m)也可以表示成(qx+k)(px+m);所以b有两种情况pk+mq,pm+qk;这里要注意;
代码:
#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<vector>
#include<map>
#include<string>
using namespace std;
typedef long long LL;
/*
const int MAXN=1e5+100;
map<string,bool>mp;
char* tostring(LL x){
char s[12];
int tp=0;
while(x){
s[tp++]=x%10+'0';
x/=10;
}
s[tp]='\0';
reverse(s,s+tp);
return s;
}
void db(){
mp.clear();
for(int i=2;i<100000;i++){
if(!mp[tostring(i)])
for(LL j=(LL)i*i;j<=(LL)3000000000;j+=i){
mp[tostring(j)]=true;
}
}
}
int main(){
int T,a,b,c;
scanf("%d",&T);
db();
while(T--){
scanf("%d%d%d",&a,&b,&c);
if(a+b+c<4){
puts("NO");continue;
}
if(mp[tostring((LL)a+b+c)])puts("YES");
else puts("NO");
}
return 0;
}
*/
int main(){
LL a,b,c,p,q,m,k;
int T;
cin>>T;
while(T--){
cin>>a>>b>>c;
bool ans=false;
for(int p=1;p*p<=a;p++){
if(a%p==0){
q=a/p;
for(int k=1;k*k<=c;k++){
if(c%k==0){
m=c/k;
if(q*k+m*p==b||p*k+m*q==b)ans=true;
}
if(ans)break;
}
}
if(ans)break;
}
if(ans)puts("YES");
else puts("NO");
}
return 0;
}
来源:https://www.cnblogs.com/handsomecui/p/5283025.html


































































