Jam's math problem
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 182 Accepted Submission(s): 92
Problem Description
Jam has a math problem. He just learned factorization.
He is trying to factorize ax
2
+bx+c
into the form of
pqx
2
+(qk+mp)x+km=(px+k)(qx+m)
.
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.
He is trying to factorize ax






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
T
, means there are
T(1≤T≤100)
cases
Each case has one line,the line has 3
numbers
a,b,c(1≤a,b,c≤100000000)


Each case has one line,the line has 3


Output
You should output the "YES" or "NO".
Sample Input
2 1 6 5 1 6 4
Sample Output
YES NOHintThe first case turn $x^2+6*x+5$ into $(x+1)(x+5)$
ax2+bx+c => pqx2+(qk+mp)x+km=(px+k)(qx+m)pqx^2+(qk+mp)x+km=(px+k)(qx+m)pqx2+(qk+mp)x+km=(px+k)(qx+m)
如果有这样的转换,p,k,q,m四个数要正整数,由十字相乘相关理论我们能知道,如果要有p,k,q,m,那么首先要有解,所以b*b-4*a*c要>0,然而因为p,k,q,m是正整数,所以代表x1,x2都是有理数,有理数是什么鬼呢?就是解不带根号,我们知道有求根公式,其中2*a,-b都保证是自然数了,如果根号下b*b-4*a*c也保证是有理数我们就就能保证解是自然数,那么如何保证根号下b*b-4*a*c是有理数呢?那么b*b-4*a*c就是平方数啦~
然后我们根据推论,就能得到AC代码:
#include<stdio.h>
#include<string.h>
#include<math.h>
using namespace std;
#define ll long long int
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
ll a,b,c;
scanf("%I64d%I64d%I64d",&a,&b,&c);
double d=b*b-4*a*c;
if(d>1e-10&&int(sqrt(d))==sqrt(d))
{
printf("YES\n");
}
else
{
printf("NO\n");
}
}
}