Affinity numberTime
limit:2000/1000 MS (java/others) Memory limit:65536/32768 K (java/others)
Total submission (s): 20775 Accepted Submission (s): 12590
Problem Description
The ancient Greek mathematician Pythagoras found in the study of natural numbers that the sum of 220 of all true approximations (i.e. not their own approximations) is:
1+2+4+5+10+11+20+22+44+55+110=284.
and 284 of all true approximate is 1, 2, 4, 71, 142, add up to exactly 220.
People were amazed at the number. and called affinity numbers. In general speaking. Assuming that the sum of the true approximations of a number is one of the two numbers, then the two numbers are the affinity numbers.
Your task is to write a program. Infer whether a given two number is a pro-numeric
Input data The first row includes a number m, followed by a M row, one instance per line, including two integers, a, B. Among them 0 <= a, b <= 600000;
Output for each test instance. Assuming that A and B are affinity numbers, the output is yes. Otherwise output No.
Sample Input
2220 284100 200
Sample Output
YESNO
A water problem.
#include <cstdio> #include <cstring> #include <algorithm> #include <iostream>using namespace Std;int ok;void tt (int x, int y) { int sum=0; for (int i=1; i<=x/2; i++) { if (x%i==0) sum+=i; } if (sum==y) ok++;} int main () { int n; int a, B; scanf ("%d", &n); while (n--) { ok=0; scanf ("%d%d", &a, &b); TT (A, b); TT (b, a); if (ok==2) printf ("yes\n"); else printf ("no\n"); } return 0;}
HDU 2040: Affinity number