bool is_AffinityNumber(AffinityNumber_t *AN) { if (NULL == AN) { cerr << "AN is a bad AffinityNumber peer.\n"; exit(EXIT_FAILURE); } int sum1 = 0, sum2 = 0; for (int i = 1; i < AN->number1; i++) if (0 == AN->number1 % i) sum1 += i; for (int i = 1; i < AN->number2; i++) if (0 == AN->number2 % i) sum2 += i; return (sum1 == AN->number2) && (sum2 = AN->number1); }
#include <iostream> #include <cstdlib> using namespace std; struct AffinityNumber_t { int number1; int number2; }; bool is_AffinityNumber(AffinityNumber_t *AN); int main() { int M; cin >> M; AffinityNumber_t *AN = new AffinityNumber_t[M]; for (int i = 0; i < M; i++) { cin >> AN[i].number1 >> AN[i].number2; } for (int i = 0; i < M; i++) { if (is_AffinityNumber(&AN[i])) cout << "YES" << endl; else cout << "NO" << endl; } return 0; } bool is_AffinityNumber(AffinityNumber_t *AN) { if (NULL ==