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. Chart.js | HTML5 Charts for your website.

    Chart.js | HTML5 Charts for your website. Chart.js

  2. #292 (div.2) D.Drazil and Tiles (贪心+bfs)

    Description Drazil created a following problem about putting  ×  tiles into an n × m grid: "The ...

  3. catkin_simple 的使用

    Catkin simple 可用于规范catkin package, 并简化CMakeLists  Dependencies are just listed once as build-depend  ...

  4. IOS添加多个按钮在导航栏

    UIView *customView = [[UIView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 75.0f, 30.0f)]; UIButton * ...

  5. Beauty of Array(模拟)

    M - M Time Limit:2000MS     Memory Limit:32768KB     64bit IO Format:%lld & %llu Submit Status P ...

  6. Memcached安装,操作,用C#操作

    本文来自:http://li19910722.blog.163.com/blog/static/136856822201406103313163/ 1:安装 下载Memcache:http://cod ...

  7. atitit.导出excel的设计----查询结果 导出为excel的实现java .net php 总结

    atitit.导出excel的设计----查询结果 导出为excel的实现java .net php 总结 1. 基本的流程 查询获得list 读取jsp的table获得标题and 字段的map to ...

  8. with ffmpeg to encode video for live streaming and for recording to files for on-demand playback

    We've been doing some experimentation with ffmpeg to encode video for live streaming and for recordi ...

  9. JavaScript关闭浏览器

    (*^__^*) 嘻嘻……,以前我找关闭浏览器选项卡的代码找不到,我还以为要用后台代码关呢?今天发现只要简单2句JavaScipt代码就可以了.看来很多东西还是在于平时的积累啊的说! 模仿延儿的口气了 ...

  10. achartengine 实现平行线 动态数据 x轴动态移动

    achartengine做平行线的时候经常会遇到: java.lang.IndexOutOfBoundsException: Invalid index 1, size is 1 at java.ut ...