BestCoder Round #70 Jam's math problem(hdu 5615)

Problem Description

Jam has a math problem. He just learned factorization. He is trying to factorize ax^2+bx+cax?2??+bx+c into the form of pqx^2+(qk+mp)x+km=(px+k)(qx+m)pqx?2??+(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 TT, means there are T(1 \leq T \leq 100 )T(1≤T≤100) cases

Each case has one line,the line has 33 numbers a,b,c (1 \leq a,b,c \leq 100000000)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

Copy

YES
NO

Hint

The first case turn x^2+6*x+5x?2??+6∗x+5 into (x+1)(x+5)(x+1)(x+5)

题意:给你一个一元二次方程的三个系数a ,b,c问你是否能用十字相乘的方法分解这个式子

题解:直接暴力枚举,当然要优化下枚举的方法,不然会超时滴,优化:因为最大数据是一亿,一亿可以分解为一万乘一万,因为这样我们分解的两个数一定不可能超过一万,先将c的所有因子存在数组中,然后在计算出a的所有因子,一个一个试即可

#include<stdio.h>
#include<string.h>
#include<string>
#include<math.h>
#include<algorithm>
#define LL long long
#define PI atan(1.0)*4
#define DD doublea
#define MAX 10100
#define mod 10007
using namespace std;
int ans[MAX];
int main()
{
    int n,m,j,i,t,k;
    int a,b,c,Min1,Min2;
	scanf("%d",&t);
	while(t--)
	{
	    scanf("%d%d%d",&a,&b,&c);
	    Min1=min(a,10000);
	    Min2=min(c,10000);
	    k=1;n=m=1;
	    for(i=1;i<=Min2;i++)
	    {
	    	n=c/i;
	    	if(n*i==c)
	    		ans[k++]=i;
	    }
	    int flag=0;
	    for(i=1;i<=Min1;i++)
	    {
	    	m=a/i;
	    	if(i*m==a)
	    	{
	    		for(j=1;j<k;j++)
	    		{
	    			if((i*ans[j]+m*(c/ans[j])==b)||(m*ans[j]+i*(c/ans[j])==b))
	    			{
	    				flag=1;
	    				break;
	    			}
	    		}
	    	}
	    	if(flag)
	    	    break;
	    }
	    if(flag) printf("YES\n");
	    else printf("NO\n");
	}
	return 0;
}

  

BestCoder Round #70 Jam's math problem(hdu 5615)

时间: 2024-10-06 01:41:20

BestCoder Round #70 Jam's math problem(hdu 5615)的相关文章

BestCoder Round #29——A--GTY&#39;s math problem(快速幂(对数法))、B--GTY&#39;s birthday gift(矩阵快速幂)

GTY's math problem Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 0    Accepted Submission(s): 0 Problem Description GTY is a GodBull who will get an Au in NOI . To have more time to learn alg

hdu 5615 Jam&#39;s math problem(十字相乘判定)

d. Jam有道数学题想向你请教一下,他刚刚学会因式分解比如说,x^2+6x+5=(x+1)(x+5) 就好像形如 ax^2+bx+c => pqx^2+(qk+mp)x+km=(px+k)(qx+m) 但是他很蠢,他只会做p,q,m,kp,q,m,k为正整数的题目 请你帮助他,问可不可以分解 题意就是问一个一元二次方程能不能进行十字相乘的分解? s. 官方题解:第一道题比较简单,可以说是简单的模拟题,我们考虑到a,b,c都是10^9??的,所以我们决定要把时间复杂度降下来, 对于每一个数,因为

Jam&#39;s math problem(思维)

Jam's math problem Submit Status Practice HDU 5615 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

HDU - 1757 A Simple Math Problem (构造矩阵)

Description Lele now is thinking about a simple function f(x). If x < 10 f(x) = x. If x >= 10 f(x) = a0 * f(x-1) + a1 * f(x-2) + a2 * f(x-3) + -- + a9 * f(x-10); And ai(0<=i<=9) can only be 0 or 1 . Now, I will give a0 ~ a9 and two positive in

HDU 5055 Bob and math problem(结构体)

主题链接:http://acm.hdu.edu.cn/showproblem.php?pid=5055 Problem Description Recently, Bob has been thinking about a math problem. There are N Digits, each digit is between 0 and 9. You need to use this N Digits to constitute an Integer. This Integer need

hdu 6182A Math Problem(快速幂)

You are given a positive integer n, please count how many positive integers k satisfy kk≤nkk≤n. InputThere are no more than 50 test cases. Each case only contains a positivse integer n in a line. 1≤n≤10^18OutputFor each test case, output an integer i

HDU 5055 Bob and math problem(简单贪心)

http://acm.hdu.edu.cn/showproblem.php?pid=5055 题目大意: 给你N位数,每位数是0~9之间.你把这N位数构成一个整数. 要求: 1.必须是奇数 2.整数的前面没有0 3.找到一个最大的整数 如果满足1.2.3条件,就输出这个数,不满足就输出-1. 给个例子 3 1 0 0 这个构成的奇数是001,这个数前面有0,应该输出-1 解题思路: 对给的N个数升序排序. 然后最小的开始找,找到一个奇数,然后把它放在最左边. 然后判断这个数是否,满足要求.满足要

A simple greedy problem(hdu 4976)

题意:有n个小兵,每个小兵有a[i]血量,第一个人每次只能对一个小兵砍一滴血,第二个人每次对所有生存的小兵砍一滴血. 最后看第一个人最多可以砍杀几个小兵. /* 首先,如果所有小兵的血量都不同的话,我们可以杀死所有的小兵,如果所以我们应该尽量使小兵血量不同, 也就是在不能将某个小兵一击致命的情况下,对某个某个血量相同的小兵砍一刀,使其血量不同. 预处理出c[i]表示i血量这个位置上的小兵是由c[i]血量的小兵砍过来的. dp[i][j]表示进行了i轮之后,留有的砍兵机会为j次的最大值. dp[i

BestCoder Round #29 1003 (hdu 5172) GTY&#39;s gay friends [线段树 判不同 预处理 好题]

传送门 GTY's gay friends Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 264    Accepted Submission(s): 57 Problem Description GTY has n gay friends. To manage them conveniently, every morning he o