hdu5615(基础)

43 篇文章 0 订阅

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.
 

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
  
  
2 1 6 5 1 6 4
 

Sample Output
  
  
YES NO
Hint
The 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
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

bokzmm

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值