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

  1. 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;这里要注意;
代码:
 

  1. #include<iostream>
  2. #include<cstdio>
  3. #include<cmath>
  4. #include<algorithm>
  5. #include<cstring>
  6. #include<vector>
  7. #include<map>
  8. #include<string>
  9. using namespace std;
  10. typedef long long LL;
  11. /*
  12. const int MAXN=1e5+100;
  13. map<string,bool>mp;
  14. char* tostring(LL x){
  15. char s[12];
  16. int tp=0;
  17. while(x){
  18. s[tp++]=x%10+'0';
  19. x/=10;
  20. }
  21. s[tp]='\0';
  22. reverse(s,s+tp);
  23. return s;
  24. }
  25. void db(){
  26. mp.clear();
  27. for(int i=2;i<100000;i++){
  28. if(!mp[tostring(i)])
  29. for(LL j=(LL)i*i;j<=(LL)3000000000;j+=i){
  30. mp[tostring(j)]=true;
  31. }
  32. }
  33. }
  34. int main(){
  35. int T,a,b,c;
  36. scanf("%d",&T);
  37. db();
  38. while(T--){
  39. scanf("%d%d%d",&a,&b,&c);
  40. if(a+b+c<4){
  41. puts("NO");continue;
  42. }
  43. if(mp[tostring((LL)a+b+c)])puts("YES");
  44. else puts("NO");
  45. }
  46. return 0;
  47. }
  48. */
  49. int main(){
  50. LL a,b,c,p,q,m,k;
  51. int T;
  52. cin>>T;
  53. while(T--){
  54. cin>>a>>b>>c;
  55. bool ans=false;
  56. for(int p=;p*p<=a;p++){
  57. if(a%p==){
  58. q=a/p;
  59. for(int k=;k*k<=c;k++){
  60. if(c%k==){
  61. m=c/k;
  62. if(q*k+m*p==b||p*k+m*q==b)ans=true;
  63. }
  64. if(ans)break;
  65. }
  66. }
  67. if(ans)break;
  68. }
  69. if(ans)puts("YES");
  70. else puts("NO");
  71. }
  72. return ;
  73. }

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. LeeCode-Invert Binary Tree

    Invert a binary tree. 4 / \ 2 7 / \ / \ 1 3 6 9 to 4 / \ 7 2 / \ / \ 9 6 3 1 /** * Definition for a ...

  2. SQL With(递归 CTE 查询)

    本文来自:http://www.cnblogs.com/smailxiaobai/archive/2012/01/16/2323291.html 指定临时命名的结果集,这些结果集称为公用表表达式 (C ...

  3. ubuntu 步步为营之uclinux编译和移植(完整版)

    本节主要包含(ubuntu10.04) 一,linux下的经常使用压缩解压缩命令 二,环境建立 三,内核编译 四,移植 一,linux下的经常使用压缩解压缩命令 在linux下常见的压缩文件格式有ta ...

  4. Android设备定制为永不锁屏

    Android系统的锁屏时间存放在Setting数据库中,字段为Settings.System.SCREEN_OFF_TIMEOUT.查看 DatabaseHelper.java文件可以找到: fra ...

  5. 9.5 在 C# 中使用 F# 库

    9.5 在 C# 中使用 F# 库 像 C# 一样,F# 也是一种静态类型的语言,就是说,编译器知道每一个值的类型,以及类方法和属性的签名.对于与 C# 的互操作性来说.这是很重要的,由于,编译器能够 ...

  6. 有关Oracle cvu和cvuqdisk

    有关Oracle cvu和cvuqdisk cvu的下载链接: http://www.oracle.com/technetwork/products/clustering/downloads/cvu- ...

  7. C# 热水器

    需求分析:现在有一个烧水器假设水温升高到100度为开水请用设计程序模拟整个烧水的过程,打开热水器,当水温达到95度时报警器开始发出警报,水温达到100度时,断开热水器电源. 我们使用常规的思维去分析这 ...

  8. Starting httpd:Could not reliably determine the server's fully qualified domain name

    #service httpd start #Starting httpd: httpd: Could not reliably determine the server's fully qualifi ...

  9. C# 限制Text只能输入数字

    private void InputNumber(KeyPressEventArgs e) { //如果输入的不是数字键,也不是回车键.Backspace键,则取消该输入 && e.K ...

  10. WEB标准:标准定义、好处、名词解释、常用术语、命名习惯、浏览器兼容、代码书写规范

    1. WEB标准是什么? “WEB标准”是一系列标准的总称.一般的误区经常把WEB标准说成DIV+CSS.准确的说法应该是:采用W3C推荐的WEB标准中的XHTML1.1结合CSS2.0 样式表制作页 ...