zoukankan      html  css  js  c++  java
  • HDU 2092 整数解

    整数解

    Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
    Total Submission(s): 33425    Accepted Submission(s): 11730


    Problem Description
    有二个整数,它们加起来等于某个整数,乘起来又等于另一个整数,它们到底是真还是假,也就是这种整数到底存不存在,实在有点吃不准,你能快速回答吗?看来只能通过编程。
    例如:
    x + y = 9,x * y = 15 ? 找不到这样的整数x和y
    1+4=5,1*4=4,所以,加起来等于5,乘起来等于4的二个整数为1和4
    7+(-8)=-1,7*(-8)=-56,所以,加起来等于-1,乘起来等于-56的二个整数为7和-8
     

     

    Input
    输入数据为成对出现的整数n,m(-10000<n,m<10000),它们分别表示整数的和与积,如果两者都为0,则输入结束。
     

     

    Output
    只需要对于每个n和m,输出“Yes”或者“No”,明确有还是没有这种整数就行了。
     

     

    Sample Input
    9 15 5 4 1 -56 0 0
     

     

    Sample Output
    No Yes Yes
     

     

    Author
    qianneng
     

     

    Source
    迎接新学期——超级Easy版热身赛
     1 /*思路:利用x1+x2=n;x1*x2=m;两式求出(x1-x2)^2=n*n-4*m;判断该数能否求出整数解,
     2 如果能的话再将该数与m相加求x1,如果x1为整数,则说明方程有整数解,反之,无整数解
     3 */
     4 #include <bits/stdc++.h>
     5 using namespace std;
     6 int main()
     7 {
     8     int n,m;
     9     int a,b,c;
    10     while(cin>>n>>m)
    11     {
    12         if(n==0&&m==0)
    13             break;
    14         else
    15         {
    16             a=n*n-4*m;
    17             b=sqrt(a);
    18             if(b*b!=a)
    19                 cout<<"No"<<endl;
    20             else
    21             {
    22                 c=b+n;
    23                 if(c%2==0)
    24                     cout<<"Yes"<<endl;
    25                 else cout<<"No"<<endl;
    26             }
    27         }
    28     }
    29     return 0;
    30 }
  • 相关阅读:
    interview ms1 N_Dorm
    interview ms1 robert move **
    LeetCode OJ-- Jump Game II **
    LeetCode OJ-- Jump Game
    LeetCode OJ-- Palindrome Partitioning II ***
    LeetCode OJ--Palindrome Partitioning **
    LeetCode OJ--Palindrome Number
    LeetCode OJ-- Linked List Cycle II **
    3dContactPointAnnotationTool开发日志(十一)
    3dContactPointAnnotationTool开发日志(十)
  • 原文地址:https://www.cnblogs.com/ECJTUACM-873284962/p/6366096.html
Copyright © 2011-2022 走看看