1038: Affinity number time limit: 1 Sec memory limit: MB
Submitted by: 254 Resolution: 208
Submitted State [Discussion Version] Title 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 an affinity number.
Input input data The first line contains a number m, followed by a M line, an instance of each row, containing two integers, a, b, 0 <=, 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
Hint Source
#include <iostream>
using namespace Std;
int result (int n) {
int i,s=0;
for (i=1;i<n;i++) {
if (n%i==0) {
S=s+i;
}
}
return s;
}
int main () {
int n,i,a,b;
cin>>n;
for (i=0;i<n;i++) {
cin>>a>>b;
if (Result (a) ==b&&result (b) ==a) cout<< "YES" <<endl;
else cout<< "NO" <<endl;
}
return 0;
}
1038: Affinity Number