hdu5616 Jam's math problem
来源:互联网 发布:软件开发技术员招聘 编辑:程序博客网 时间:2024/06/05 17:53
Jam’s math problem
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 990 Accepted Submission(s): 474
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(1≤T≤100) cases
Each case has one line,the line has 3 numbers a,b,c(1≤a,b,c≤100000000)
分析:题意就化成多项式形式化成十字相乘的形式。直接想到两个for()枚举a,c的四个因子。只要到sqrt(a)就行了。
#include<iostream>#include<string>#include<cstring>#include<algorithm> #include<cmath>using namespace std;int main(){ long long a,b,c; int t,flag; scanf("%d",&t); while(t--) { flag=0; long long p,k; scanf("%lld %lld %lld",&a,&b,&c); for(long long i=1;i<=sqrt(a);i++) { if(a%i) continue;for(long long j=1;j<=sqrt(c);j++)//枚举由两个因子乘的一个,这样快些 { if(c%j) continue; p=a/i,k=c/j; if((i*j+p*k==b)||(i*k+j*p==b))//有两个形式,别忘了 { printf("YES\n"); flag=1; break; } } if(flag) break; } if(!flag) printf("NO\n"); } return 0;}
0 0
- hdu5616 Jam's math problem
- Jam's math problem
- Jam's math problem
- hdu5616 Jam's balance
- HDU5616 Jam's balance
- HDU5615:Jam's math problem
- Jam's math problem<hdoj5615>
- I - Jam's math problem
- HDU5615 Jam's math problem
- HDOJ 5615 Jam's math problem
- HDOJ 5615-Jam's math problem【数学】
- HDU 5615 Jam's math problem
- HDU 5615 Jam's math problem
- Jam's math problem(HDU5615)
- HDU 5615 Jam's math problem
- 杭电5615 Jam's math problem
- hdu 5615 Jam's math problem
- HDU-5615-Jam's math problem
- 安装linux镜像文件
- IOS学习之——手势解锁
- Java 快速排序算法
- Long.valueOf()作用
- linux获取当前图形界面的分辨率的小程序
- hdu5616 Jam's math problem
- apns服务
- Python学习笔记(二)——Python CGI编程
- Maven新建项目报错
- 致联系报考我免试研究生的同学们-山世光 研究员-中科院计算所
- leetcode之Same Tree
- BZOJ 1483: [HNOI2009]梦幻布丁
- ionic云开发系列二之调用webservice
- HDOJ 2048 神、上帝以及老天爷