hdu5615(基础)
来源:互联网 发布:手机美化主题软件 编辑:程序博客网 时间:2024/06/11 05:10
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 factorizeax2+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
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 has3 numbers a,b,c(1≤a,b,c≤100000000)
Each case has one line,the line has
Output
You should output the "YES" or "NO".
Sample Input
21 6 51 6 4
Sample Output
YESNOHintThe 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;}
0 0
- hdu5615(基础)
- HDU5615:Jam's math problem
- HDU5615 Jam's math problem
- Jam's math problem(HDU5615)
- hdu5615 Jam's math problem (BestCoder Round #70)
- 第二周周赛——加油 题解(分别出自HDU5615,HDU5586,codeforces 319B,codeforces 518C,codeforces 548D)
- 基础
- 基础
- 基础
- 基础
- 基础
- 基础
- 基础
- 基础
- 基础
- 基础
- 基础
- 基础
- vim 配合各种插件工具的详细使用方法收集
- BZOJ_P3670 [NOI2014]动物园(字符串+KMP)
- Object类的方法
- AsyncTask 用法介绍
- ArcGIS api for JavaScript 制作统计专题图
- hdu5615(基础)
- linux进程读写锁
- GridView 显示不全的解决办法
- 深入理解Lua的闭包一:概念和应用
- 设计模式 —— 单例模式, Singleton Patttern
- 【NOIP2012提高组】开车旅行
- dynamic
- 新工具︱微软Microsoft Visual Studio的R语言模块下载试用Ing...(尝鲜)
- 决策树之CART算法