zoukankan      html  css  js  c++  java
  • Jam's math problem(思维)

    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]='';
        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;
    }
  • 相关阅读:
    centos下安装Anaconda
    centos下安装python2.7.9和pip以及数据科学常用的包
    mysql基础(5)-关联(mysql+pandas)
    mysql基础(4)-数据导入
    mysql基础(3)-高级查询
    mysql基础(2)-数据处理(mysql+pandas)
    mysql基础(1)-基本操作
    创建线程的三种方法
    Jar 包 及运行Jar包
    导出成可运行jar包时所遇问题的解决办法
  • 原文地址:https://www.cnblogs.com/handsomecui/p/5283025.html
Copyright © 2011-2022 走看看