Affinity number Time limit:1000ms Memory limit:65536k have questions? Dot here ^_^ The topic describes if the factor of a and equals b,b factor and equals A, and a≠b, is called A, B is the affinity number pair. For example, the sum of all true approximations of 220 (i.e. not their own approximations) is: 1+2+4+5+10+11+20+22+44+55+110=284. 284 of all true approximate and for: 1+2+4+71+142=220. 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 row, an instance per line, containing two integers, a, a, and a 0≤a,b≤99999. 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:
#include <stdio.h> #include <string.h> #include <math.h>int main () {int n, m;int dd, ff;int i, J;int T;sca NF ("%d", &t), while (t--) {scanf ("%d%d", &n, &m); dd=1;ff=1; for (i=2; i<=sqrt (n); i++) {if (n%i==0) {dd=dd+i+ (n/i);}} for (j=2; j<=sqrt (m); j + +) {if (m%j==0) {ff=ff+j+ (m/j);}} if (dd==m && ff==n) {printf ("yes\n");} else{printf ("no\n");}} return 0;} /**************************************problem Id:sdut OJ 1221 result:accepted take memory:276k take time:0ms Submit T ime:2015-01-09 19:49:49 **************************************/
Sdut OJ 1221 Affinity Number (Find a number n all factors, only need violence: 2->SQRT (n))