Jam's math problem
 

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)$
         
 题解:
 乍一看数据那么大,推出了(q+m)(p+k)=a+b+c;想着只要a+b+c不是质数就好了,就傻傻的打了个3亿的质数表,差点把我电脑运行爆,弄到一半赶紧关了,肯定超时了,看了别人的才知道自己想复杂了,不用那么麻烦的,暴力下判断就好了;由于(px+k)*(qx+m)也可以表示成(qx+k)(px+m);所以b有两种情况pk+mq,pm+qk;这里要注意;
代码:
 

#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<vector>
#include<map>
#include<string>
using namespace std;
typedef long long LL;
/*
const int MAXN=1e5+100;
map<string,bool>mp;
char* tostring(LL x){
char s[12];
int tp=0;
while(x){
s[tp++]=x%10+'0';
x/=10;
}
s[tp]='\0';
reverse(s,s+tp);
return s;
}
void db(){
mp.clear();
for(int i=2;i<100000;i++){
if(!mp[tostring(i)])
for(LL j=(LL)i*i;j<=(LL)3000000000;j+=i){
mp[tostring(j)]=true;
}
}
}
int main(){
int T,a,b,c;
scanf("%d",&T);
db();
while(T--){
scanf("%d%d%d",&a,&b,&c);
if(a+b+c<4){
puts("NO");continue;
}
if(mp[tostring((LL)a+b+c)])puts("YES");
else puts("NO");
}
return 0;
}
*/
int main(){
LL a,b,c,p,q,m,k;
int T;
cin>>T;
while(T--){
cin>>a>>b>>c;
bool ans=false;
for(int p=;p*p<=a;p++){
if(a%p==){
q=a/p;
for(int k=;k*k<=c;k++){
if(c%k==){
m=c/k;
if(q*k+m*p==b||p*k+m*q==b)ans=true;
}
if(ans)break;
}
}
if(ans)break;
}
if(ans)puts("YES");
else puts("NO");
}
return ;
}

Jam's math problem(思维)的更多相关文章

  1. HDU 5615 Jam's math problem

    Jam's math problem Problem Description Jam has a math problem. He just learned factorization.He is t ...

  2. 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 ...

  3. hdu 5615 Jam'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)(q ...

  4. hdu 5615 Jam's math problem(判断是否能合并多项式)

    方法一:由十字相乘相关理论我们能知道,如果要有p,k,q,m,那么首先要有解,所以b*b-4*a*c要>0,然而因为p,k,q,m是正整数,所以代表x1,x2都是有理数,有理数是什么鬼呢?就是解 ...

  5. hdu 1757 A Simple Math Problem (乘法矩阵)

    A Simple Math Problem Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Ot ...

  6. HDU1757 A Simple Math Problem 矩阵快速幂

    A Simple Math Problem Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Ot ...

  7. hdu----(5055)Bob and math problem(贪心)

    Bob and math problem Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Oth ...

  8. hdu------(1757)A Simple Math Problem(简单矩阵快速幂)

    A Simple Math Problem Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Ot ...

  9. FZYZ-2071 A Simple Math Problem IX

    P2071 -- A Simple Math Problem IX 时间限制:1000MS      内存限制:262144KB 状态:Accepted      标签:    数学问题-博弈论    ...

随机推荐

  1. Word Ladder II 解答

    Question Given two words (beginWord and endWord), and a dictionary's word list, find all shortest tr ...

  2. LeeCode-Remove Duplicates from Sorted List

    Given a sorted linked list, delete all duplicates such that each element appear only once. For examp ...

  3. 【斗地主技巧】斗地主算法逻辑中的天之道<转>

    ******************************************************************** 作者比较喜欢玩斗地主,所以经常搜集一些网友斗地主的心得,下面这 ...

  4. 回溯算法-C#语言解决八皇后问题的写法与优化

    结合问题说方案,首先先说问题: 八皇后问题:在8X8格的国际象棋上摆放八个皇后,使其不能互相攻击,即任意两个皇后都不能处于同一行.同一列或同一斜线上,问有多少种摆法. 嗯,这个问题已经被使用各种语言解 ...

  5. ERROR: HHH000388: Unsuccessful: create table

    做SSH整合的时候,总是出现错误信息: 类似这样: : HHH000388: Unsuccessful: create table right (right_code varchar(255) not ...

  6. CF 338 D GCD Table(CRT)

    转载请注明出处,谢谢http://blog.csdn.net/ACM_cxlove?viewmode=contents    by---cxlove 给定一个序列,a[1 ..k],问是否存在(i , ...

  7. jQuery支持移动Mobile的DOM元素移动和缩放插件

    jQuery Panzoom是一款很有用的HTML DOM元素平移和缩放jQuery和CSS3插件. Panzoom利用CSS transforms 和 matrix函数来为浏览器进行硬件(GPU)加 ...

  8. 一个操作EXCEL的C#类ExcelUtils

    近期在公司里一直从事服务类的工作,涉及到非常多excel的处理.部分工作内容是每天反复的,仅仅是每天的数据不同而已.我遇到的一个问题是客户每天发送的几种数据有些excel中的字段顺序是一致的,有些是不 ...

  9. android——背景颜色渐变(梯度变化)

    首先在drawable文件夹下面新建一个xml文件,起名为bgcolor.xml. 代码如下: <?xml version="1.0" encoding="utf- ...

  10. GIS-开发例程、源代码、MapXtreme、Map (转)

    [原创]MapXtreme实用技巧与源码10例 普通图片生成MapInfo格式电子地图的步骤  http://blog.csdn.net/hmbb2008/category/184134.aspx 基 ...