hdoj--5615--Jam's math problem(数学)(交叉相乘)

本文探讨了一个特定的数学问题,即如何将形式为ax²+bx+c的二次方程分解为pqx²+(qk+mp)x+km=(px+k)(qx+m)的形式,特别关注于寻找正整数p、q、m和k的情况下方程是否可分解。


Jam's math problem

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


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

Source
我记得以前应该是这么做的,找出二次项系数跟常数项个子所有因子,然后组合,看是否可以组合产生一次项系数,,,本来以为会超时的,但是水过了 - - ||



#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
int a[10000+10],b[10000+10];
int main()
{
	int t;
	scanf("%d",&t);
	while(t--)
	{
		memset(a,0,sizeof(a));
		memset(b,0,sizeof(b));
		int A,B,C;
		scanf("%d%d%d",&A,&B,&C);
		int cnt1,cnt2;
		cnt1=cnt2=0;
		for(int i=1;i<=sqrt(A);i++)
		if(A%i==0)
		a[cnt1++]=i;
		
		for(int i=1;i<=sqrt(C);i++)
		if(C%i==0)
		b[cnt2++]=i;
		
		int f=false;
		for(int i=0;i<cnt1;i++)
		{
			int p=a[i];
			int q=A/a[i];
			for(int j=0;j<cnt2;j++)
			{
				int k=b[j];
				int m=C/b[j];
				if(m*p+q*k==B)
				{
					f=true;
					break;
				}
				if(p*k+q*m==B)
				{
					f=true;
					break;
				}
			}
			if(f) break;
		}
		if(f) printf("YES\n");
		else printf("NO\n");
	}
	return 0;
}

 
 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值