HDOJ 2040 亲和数

简介: HDOJ 2040 亲和数

Problem Description


古希腊数学家毕达哥拉斯在自然数研究中发现,220的所有真约数(即不是自身的约数)之和为:


1+2+4+5+10+11+20+22+44+55+110=284。


而284的所有真约数为1、2、4、71、 142,加起来恰好为220。人们对这样的数感到很惊奇,并称之为亲和数。一般地讲,如果两个数中任何一个数都是另一个数的真约数之和,则这两个数就是亲和数。


你的任务就编写一个程序,判断给定的两个数是否是亲和数


Input

输入数据第一行包含一个数M,接下有M行,每行一个实例,包含两个整数A,B; 其中 0 <= A,B <= 600000 ;


Output

对于每个测试实例,如果A和B是亲和数的话输出YES,否则输出NO。


Sample Input

2

220 284

100 200


Sample Output

YES

NO

import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        while(n-->0){
            int a = sc.nextInt();
            int b = sc.nextInt();
            boolean isSaf =Saf(a,b);
            if(isSaf){
                System.out.println("YES");
            }else{
                System.out.println("NO");
            }
        }
    }
    private static boolean Saf(int a, int b) {
        int sumA = 1;
        int sumB = 1;
        for(int i=2;i<=a/2;i++){
            if(a%i==0){
                sumA = sumA+i;
            }
        }
        for(int i=2;i<=b/2;i++){
            if(b%i==0){
                sumB = sumB+i;
            }
        }
        if(sumA==b&&sumB==a){
            return true;
        }else{
            return false;
        }
    }
}
目录
相关文章
|
7月前
hdoj 1907
这是一道博弈的题,准确说是尼姆博弈,只要判断各项的异或值即可。
19 0
|
7月前
|
Java C++
hdoj 1715 大菲波数
先java代码
32 1
HDOJ 1323 Perfection(简单题)
HDOJ 1323 Perfection(简单题)
104 0
|
安全
HDOJ 2022 海选女主角
HDOJ 2022 海选女主角
132 0
HDOJ 2013 蟠桃记
HDOJ 2013 蟠桃记
79 0
|
Java 机器学习/深度学习
HDOJ 2075 A|B?
Problem Description 正整数A是否能被正整数B整除,不知道为什么xhd会研究这个问题,来帮帮他吧。 Input 输入数据的第一行是一个数据T,表示有T组数据。
922 0
HDOJ 2056 Rectangles
Problem Description Given two rectangles and the coordinates of two points on the diagonals of each rectangle,you have to calculate the area of the intersected part of two rectangles.
960 0