Jam ' s math problem (thinking)

Source: Internet
Author: User

Jam ' s math problemSubmit Status Practice HDU 5615

Description

Jam has a math problem. He just learned factorization.He is trying to factorize into the form of < Span id= "mathjax-span-25" class= "Mi" > < Span id= "mathjax-span-30" class= "Mi" > < Span id= "mathjax-span-35" class= "Mo" > < Span id= "mathjax-span-40" class= "Mi" > /span> .He could only solve the problem in which p,q,m,k is positive numbers. Please help him determine whether the expression could is factorized with P,q,m,k being postive.

Input

The first line is a number, means there is Cases
Each case have one line,the line haveNumbers 

Output

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

Sample Input

21 6 51) 6 4

Sample Output

YESNO

Hint

The first case turn $x ^2+6*x+5$ into $ (x+1) (x+5) $          
The problem: At first glance the data is so big, launched (q+m) (p+k) =a+b+c, think as long as a+b+c is not prime, just silly to play a 300 million of the quality of the tables, almost put my computer to run a burst, half hurried off, certainly timed out, looked at others only know that they want to complicate, not so troublesome , the judgment of violence is good, because (px+k) * (QX+M) can also be expressed as (Qx+k) (px+m), so there are two cases of B pk+mq,pm+qk; here's the code:
#include <iostream>#include<cstdio>#include<cmath>#include<algorithm>#include<cstring>#include<vector>#include<map>#include<string>using namespaceStd;typedefLong LongLL;/*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)]) (ll j= (LL) i*i;j<= (LL) 3000000000;j+=i) {m        P[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;}*/intMain () {LL a,b,c,p,q,m,k; intT; CIN>>u;  while(t--) {cin>>a>>b>>C; BOOLans=false;  for(intp=1;p *p<=a;p++){            if(a%p==0) {Q=a/p;  for(intk=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"); ElsePuts"NO"); }    return 0;}

Jam ' s math problem (thinking)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.