Jam's math problem
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 881 Accepted Submission(s): 423
Problem Description
Jam has a math problem. He just learned factorization.
He is trying to factorize ax2+bx+c into the form of pqx2+(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 ax2+bx+c into the form of pqx2+(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.
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 numbers a,b,c(1≤a,b,c≤100000000)
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)$
//hdu5615题目大意:对于一个方程ax^2+bx+c=0;问是否可以通过分解a、c的因子.将方程化为(px+m)(qx+k)=0的形式.
//且(m、k、p、q大于零,a=p*q,c=m*k)
//解题思路:首先由于要求p,q,m,k都大于零,所以可以可以从1~sqrt(a)和1~sqrt(c)枚举a和c的因子。
//注:(a、c范围较大,所以就像判断素数的原理一样,只要枚举前i=sqrt(a)个数,后面的也已经通过a/i得到了)
//看是否有满足 (p*m+q*k)==b或(p*k+q*m)==b;有则存在解,输出YES,否则输出NO.
#include<stdio.h>
#include<math.h>
int main()
{
int t,a,b,c,u,n;
int p,q,m,k,flag;
scanf("%d",&t);
while(t--)
{
flag=0;
scanf("%d%d%d",&a,&b,&c);
n=sqrt(a)+1;
u=sqrt(c)+1;
for(int i=1;i<=n;i++) //枚举a的前sqrt(a)项因子
{
if(flag==1) break; //已经找到解,跳出循环。
if(a%i==0)
{
p=i;q=a/i;
for(int j=1;j<=u;j++) //枚举c的前sqrt(c)项因子
{
if(c%j==0)
{
m=j;k=c/j;
if((p*k+q*m)==b||(q*k+p*m)==b) //满足条件,flag=1,跳出循环。
{
flag=1;break;
}
}
}
}
}
if(flag==1) printf("YES\n");
else printf("NO\n");
}
return 0;
}