Jam's math problem
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 51 Accepted Submission(s): 27
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.
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)
Each case has one line,the line has 3 numbers a,b,c(1≤a,b,c≤100000000)
Output
You should output the "YES" or "NO".
Sample Input
2 1 6 5 1 6 4
Sample Output
YES NOHintThe first case turn $x^2+6*x+5$ into $(x+1)(x+5)$
题意:给你a*x^2 + b*x + c,问你能否分解因式。
思路:求两个根式,判定一下就可以了。
AC代码:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <vector>
#include <string>
#define INF 0x3f3f3f3f
#define eps 1e-8
#define MAXN (100000+10)
#define MAXM (300000+10)
#define Ri(a) scanf("%d", &a)
#define Rl(a) scanf("%lld", &a)
#define Rf(a) scanf("%lf", &a)
#define Rs(a) scanf("%s", a)
#define Pi(a) printf("%d\n", (a))
#define Pf(a) printf("%.2lf\n", (a))
#define Pl(a) printf("%lld\n", (a))
#define Ps(a) printf("%s\n", (a))
#define W(a) while((a)--)
#define CLR(a, b) memset(a, (b), sizeof(a))
#define MOD 1000000007
#define LL long long
#define lson o<<1, l, mid
#define rson o<<1|1, mid+1, r
#define ll o<<1
#define rr o<<1|1
#define PI acos(-1.0)
#pragma comment(linker, "/STACK:102400000,102400000")
#define fi first
#define se second
using namespace std;
int main()
{
int t, n, m, kcase = 1; Ri(t);
__int64 a, b, c;
W(t)
{
scanf("%I64d%I64d%I64d", &a, &b, &c);
__int64 d = b * b - 4 * a * c;
double D = b * b - 4 * a * c;
__int64 e = sqrt(D); bool flag = true;
if(e * e == d)
{
__int64 f = b - e;
if(f <= 0 || f & 1)
{
flag = false;
break;
}
f = b + e;
if(f <= 0 || f & 1)
flag = false;
}
else
flag = false;
printf(flag ? "YES\n" : "NO\n");
}
return 0;
}