Problem Description
The ancient Greek mathematician Pythagoras found in the study of natural numbers that 220 of all true approximations (i.e. not their own approximations) sum to:
1+2+4+5+10+11+20+22+44+55+110=284.
and 284 of all true approximations are 1, 2, 4, 71, 142, add up to exactly 220. People are amazed at the numbers and call it affinity numbers. Generally speaking, if any of the two numbers is the sum of the true approximations of the other number, then these two numbers are the affinity numbers.
Your task is to write a program that determines whether a given two number is a pro-and-numeric
Input data The first row contains a number m, followed by a M line, an instance of each row, containing two integers, a, a, 0 of which <= a, b <= 600000;
Output yes for each test instance if a and B are affinity numbers, otherwise output no.
Sample Input2220 284100 200
Sample Outputyesno
Public classMain { Public Static voidMain (string[] args) {Scanner in=NewScanner (system.in); intn=In.nextint (); for(intii=0;ii<n;ii++){ intA=In.nextint (); intb=In.nextint (); intT=0; List<Integer> Li =NewArraylist<integer>(); for(intI=1;i<= (A/2); i++){ if(a%i==0) {li.add (i); } } for(intI:li) {T=t+i; } if(t==b) {li.clear (); T=0; for(intI=1;i<= (B/2); i++){ if(b%i==0) {li.add (i); } } for(intI:li) {T=t+i; } if(t==a) {System.out.println ("YES"); } }Else{System.out.println ("NO"); } } } }
ACM 2040 Java Practices