hdu 2092 整数解

整数解

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


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
 


//hdu 2092 整数解

#include <iostream>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <set>
#include <vector>
#include <map>
#include <algorithm>

using namespace std;

int main(){
	int n, m;
	while(scanf("%d%d", &n, &m) != EOF && (n || m)){
	if (n == 0 && m == 0)  
        {  
            break;  
        }  
        int delta = n*n - 4 * m;  
        if (delta < 0)  
        {  
            cout << "No" << endl;  
            continue;  
        }  
        int ac = sqrt(delta);  
        if (ac*ac != delta)  
        {  
            cout << "No" << endl;  
            continue;  
        }  
        int frac_1 = n + ac;  
        int frac_2 = n - ac;  
        if (frac_1 % 2 == 0 && frac_2 % 2 == 0)  
        {  
            cout << "Yes" << endl;  
        }  
        else  
        {  
            cout << "No" << endl;  
        }  
	}
	return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值