Description if the factor of a and the factor equal to b,b and equals a, and a≠b, then A, B is an intimate 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 data the first line contains a number m, followed by a M line, an instance per line, containing two integers, a, B, where 0≤a,b≤99999. Output yes for each test instance if a and B are affinity numbers, otherwise output no.
/* All rights reserved. * File name: Test.cpp * Chen Dani * Completion Date: May 19, 2015 * Version number: v1.0 */#include <iostream>using namespace Std;int main () {in T a,b,n; cin>>n; while (cin>>a>>b) { int i,m=0,s=0; for (I=1; i<=a/2; i++) { if (a%i==0) m=m+i; } for (I=1; i<=b/2; i++) { if (b%i==0) s=s+i; } if (a==s&&b==m&&a!=b) cout<< "YES" <<endl; else cout<< "NO" <<endl; } return 0;}
Experience: Calm, thinking, clear ideas to write the code! Keep trying!
C + + brush question--1912: Affinity number