Ancient Greek mathematician Pythagoras found in the study of natural Numbers, all 220 really few (that is, is not itself a few) for the sum of:
1 + 2 + 4 + 5 + 10 + 11 + 20 + 22 + 44 + 55 + 110=284,
And all,2,4,71 really few is 1, 284, 142, add up to 220, people in such Numbers surprised, and called the number of affinity, generally speaking, if any number in the two Numbers are a number of really few, the sum of the two number is affinity,
Your task is to write a program to determine whether a given two Numbers is amicable Numbers
Input
Input data to the first line contains A number M, take A M lines, each line one instance, contains two integers A, B; The 0 <=A, B <=600000;
The Output
For each test case, if A and B were amicable Numbers output YES, otherwise NO output,
The Sample Input
2
220, 284,
100, 200,
The Sample Output
YES
NO
Code:
#include
using namespace std;
Int a, b, m, sum;
Int judge (int s)
{
Sum=0;
for(int j=1; J<=s/2; J++)
{
If (s % j==0)
Sum=sum + j;
}
Return the sum.
}
Int main ()
{
Cin> m;
for(int i=0; i
Int x, y;
Cin> a> b;
X=judge (a);
Y=judge (b);
If (x==b& & Y==a)
Printf (" YES \ n ");
The else
Printf (" \ n ");
}
}