Jam's math problem(思维)

最后都变了- 提交于 2020-02-25 02:51:16
Jam's math problem
 

Description

Jam has a math problem. He just learned factorization.  He is trying to factorize 

 into the form of 

.  He could only solve the problem in which p,q,m,k are positive numbers.  Please help him determine whether the expression could be factorized with p,q,m,k being postive.
 

Input

The first line is a number 

, means there are 

 cases 
Each case has one line,the line has 

 numbers 

 

Output

You should output the "YES" or "NO".
 

Sample Input

2 1 6 5 1 6 4
 

Sample Output

YES NO

Hint

 The first case turn $x^2+6*x+5$ into $(x+1)(x+5)$ 
         
 题解:
 乍一看数据那么大,推出了(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;
}

 

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!