HDU 2092 整数解

计算机软件开发 2024-9-25 13:49:20 93 0 来自 中国
Problem Description
有二个整数,它们加起来即是某个整数,乘起来又即是另一个整数,它们到底是真还是假,也就是这种整数到底存不存在,着实有点吃禁绝,你能快速复兴吗?看来只能通过编程。
比方:
x + y = 9,x * y = 15 ? 找不到如许的整数x和y
1+4=5,14=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
JAVA CODE
import java.util.Scanner;public class Main {    public static void main(String[] args) {        Scanner input = new Scanner(System.in);        while (input.hasNextInt()) {            int n = input.nextInt();            int m = input.nextInt();            if (n == 0 && m == 0) {                break;            }            int k = n * n - 4 * m;            if (k < 0 || ((int) Math.sqrt(k)) != Math.sqrt(k)) {                System.out.println("No");            } else {                k = (int) Math.sqrt(k);                if ((((int) (n + k) / 2) == (n + k) / 2)                        && ((int) (n - k) / 2) == (n - k) / 2) {                    System.out.println("Yes");                } else {                    System.out.println("No");                }            }        }        input.close();    }}```
您需要登录后才可以回帖 登录 | 立即注册

Powered by CangBaoKu v1.0 小黑屋藏宝库It社区( 冀ICP备14008649号 )

GMT+8, 2024-10-18 20:27, Processed in 0.167897 second(s), 32 queries.© 2003-2025 cbk Team.

快速回复 返回顶部 返回列表