Problem description the ancient Greek mathematician pedgoras found in the study of natural numbers that the sum of all the true dikes of 220 (that is, not their own dikes) is:
1 + 2 + 4 + 5 + 10 + 11 + 20 + 22 + 44 + 55 + 110 = 284.
The sum of all the true approx. Values of 284 is 1, 2, 4, 71, and 142, which is exactly 220. People are amazed at this kind of data and call it affinity. Generally, if either of the two numbers is the sum of the true approx. of the other, the two numbers are the affinity.
Your task is to write a program to determine whether the given two numbers are affinity.
The first row of input data contains a number of M, followed by m rows. Each row has an instance, which contains two integers, A and B. 0 <=a, B <=600000;
For each test instance, if A and B are the affinity numbers, output yes; otherwise, output No.
Sample Input
2220 284100 200
Sample output
YESNO
import java.io.BufferedInputStream;import java.util.*;public class Main {public static void main(String[] args) {Scanner sc=new Scanner(new BufferedInputStream(System.in));int k,m,n;k=sc.nextInt();for(int i=0;i<k;i++){m=sc.nextInt();n=sc.nextInt();fun(m,n);}}public static void fun(int m,int n){int sum1=0;int max=Math.max(m, n);int min=Math.min(m, n);for(int i=1;i<max;i++){if(max%i==0){sum1+=i;}}if(sum1==min) System.out.println("YES");else System.out.println("NO");}}