HDOJ 5615 Jam's math problem (数学题枚举)
2016-07-27 11:38
330 查看
Jam's math problem
Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u
Submit Status
Description
Jam has a math problem. He just learned factorization.
He is trying to factorize
into
the form of
.
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
,
means there are
cases
Each case has one line,the line has
numbers
Output
You should output the "YES" or "NO".
Sample Input
2
1 6 5
1 6 4
Sample Output
YES
NO
Hint
枚举求解:
#include<stdio.h>
int main()
{
int t;
__int64 a,b,c,i,j;
scanf("%d",&t);
while(t--)
{
scanf("%I64d%I64d%I64d",&a,&b,&c);
int k=0;
for(i=1;i*i<=a;i++)
{
if(a%i) //枚举p,q
continue;
for(j=1;j*j<=c;j++)
{
if(c%j) //枚举k,m
continue;
if(i*j+(a/i)*(c/j)==b||i*(c/j)+j*(a/i)==b) //<span style="white-space:pre"> </span>判断是否是方程的解
{
k=1;
break;
}
}
if(k)
break;
}
if(k)
printf("YES\n");
else
printf("NO\n");
}
return 0;
}
Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u
Submit Status
Description
Jam has a math problem. He just learned factorization.
He is trying to factorize
into
the form of
.
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
,
means there are
cases
Each case has one line,the line has
numbers
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)$
枚举求解:
#include<stdio.h>
int main()
{
int t;
__int64 a,b,c,i,j;
scanf("%d",&t);
while(t--)
{
scanf("%I64d%I64d%I64d",&a,&b,&c);
int k=0;
for(i=1;i*i<=a;i++)
{
if(a%i) //枚举p,q
continue;
for(j=1;j*j<=c;j++)
{
if(c%j) //枚举k,m
continue;
if(i*j+(a/i)*(c/j)==b||i*(c/j)+j*(a/i)==b) //<span style="white-space:pre"> </span>判断是否是方程的解
{
k=1;
break;
}
}
if(k)
break;
}
if(k)
printf("YES\n");
else
printf("NO\n");
}
return 0;
}