HDU-5615-Jam's math problem(方程求解)
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 870 Accepted Submission(s): 415
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)$感觉这道题有点坑,可能是我英语不太好吧, p,q,m,k are positive numbers。 p,q,m,k 不应该是正数吗?可是按正数处理,样例都不满足。最后看了别人的题解才知道,当作整数处理。一元二次方程的解:x1=(-b-sqrt(b*b-4*a*c))/(2*a)、x2=(-b+sqrt(b*b-4*a*c))/(2*a),刚开始面对这道题也不知道要如何求解,最后看了同学的题解恍然大悟,而且方法很简单。x1=(-1)*(k/p),x2=(-1)*(m/q).即:(-1)*(k/p)=(-b-sqrt(b*b-4*a*c))/(2*a)、(-1)*(m/q)=(-b+sqrt(b*b-4*a*c))/(2*a),因k、p、m、q是整数,(2*a)、-b也是整数,只要sqrt(b*b-4*a*c)为整数就满足,输出YES,否则输出NO.
/*2016.3.15*/
#include<stdio.h>
#include<math.h>
#include<algorithm>
using namespace std;
int main()
{
long long a,b,c,q,p,k,m,n,h;
double j;
scanf("%I64d",&n);
while(n--)
{
scanf("%I64d%I64d%I64d",&a,&b,&c);
j=b*b-4*a*c;
//m=b*b-4*a*c;
if(j>=0)
{
j=sqrt(j);//q=sqrt(m)
h=(int)j;//强制类型转换
if(j-h)//if(q*q!=m)
printf("NO\n");
else
printf("YES\n");
}
else
printf("NO\n");
}
return 0;
}