Problem:
The start of J for the For Loop is set to the small root a, resulting in not all of the approximate numbers.
Affinity numberTime
limit:2000/1000 MS (java/others) Memory limit:65536/32768 K (java/others)
Total submission (s): 26302 Accepted Submission (s): 15814
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 Input
2220 284100 200
Sample Output
YESNO
Code:
Import java.util.*;p ublic class main{public static void Main (string[] args) {Scanner cin=new Scanner (system.in); int n=cin . Nextint (); for (int i=0;i<n;i++) {int a=cin.nextint (); int b=cin.nextint (); int k=0,t=0;for (int j=1;j<a;j++) if (a% j==0) k=k+j;for (int j=1;j<b;j++) if (b%j==0) t=t+j;if (k==b&&t==a) System.out.println ("YES"); ElseSystem.out.println ("NO");}}}
HDU 2040 affinity Number (Java)