hdoj 5615 Jam's math problem (数学-因式分解)

来源:互联网 发布:苹果cms模板怎么用 编辑:程序博客网 时间:2024/05/21 10:15

Jam's math problem

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 1348    Accepted Submission(s): 606


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.
 

Input
The first line is a number T, means there are T(1T100) cases

Each case has one line,the line has 3 numbers a,b,c(1a,b,c100000000)
 

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)$
 

Source
BestCoder Round #70
 嗯,分解因式,数学学到的,最后遍历的时候b‘的值可能有两种情况,都要列出试探
#include<cstdio>#include<cmath>int main(){int t,a,b,c;scanf("%d",&t);while(t--){scanf("%d%d%d",&a,&b,&c);if(c<=0||a<=0){printf("NO\n");continue;}int m1=(int)sqrt(a*1.0);int m2=(int)sqrt(c*1.0);int b1,b2;//分解因式b'有两种情况,啊 int flag=0;for(int i=1;i<=m1;i++){if(a%i==0){for(int j=1;j<=m2;j++){if(c%j==0){b1=i*c/j+j*a/i;b2=i*j+a/i*c/j;if(b1==b||b2==b){flag=1;break;}}}}if(flag==1)break;}if(flag==1)printf("YES\n");elseprintf("NO\n"); }  return 0; } 




0 0
原创粉丝点击