Hang electric brush oj title (2092)

Integer solution

Topic Description:
There are two integers which add up to an integer equal to ride up and another integer, which in the end is true or false, this is an integer in the end it exists or not, it is a bit not sure, you can quickly answer it ? It seems only through programming.
For example:
x = Y +. 9, Y = x * 15 no such integers x and Y?
. 1 * 4 + 4 = 5,1 = 4, therefore, add up to 5, up by two integer equal to 4, 1 and 4 to
7 + (- 8) = - 1.7 * (- 8) = - 56, therefore, add up to -1, multiply the two integer equal to 7 and -8 to -56

Input

The input data is an integer of pairs of n, m (-10000 <n, m <10000), which represent the sum and product of integers, if both are 0, the input ends.

Output

Only for each n and m, output "Yes" or "No", clearly there is still no such integer on the line.

Sample Input

9 15 
5 4 
1 -56 
0 0

Sample Output

No 
Yes 
Yes

analysis:

 

∵x + y = n
∴y = n - x
∵xy = m
∴(n - x) * x = m
∴x * x - n x + m = 0
t=n*n-4*m

By the answer:

#include<stdio.h>
#include<math.h>
int main(){
	int n,m,t,t1;
	while(scanf("%d %d",&n,&m)!=EOF){
		if(n==0&&m==0)break;
		t=n*n-4*m;       //△=b*b-4*a*c 
		t1=(int)sqrt(t);    
		if(t>=0&&t==t1*t1){    //△>=0表示方程有解并且解都为整数 (关键)
			printf("Yes\n");
		}else{
			printf("No\n");
		}
	}
	return 0;
} 

 

Published 76 original articles · won praise 3 · Views 1850

Guess you like

Origin blog.csdn.net/ZhangShaoYan111/article/details/104374085
Recommended