解题思路:
定义一个判断亲和数的函数
注意事项:
参考代码:
#include<iostream>
using namespace std;
bool qinhe(int a, int b)
{
int s1 = 0, s2 = 0;
for (int i = 1; i < a; i++)
if (a%i == 0) s1 += i;
for (int i = 1; i < b; i++)
if (b%i == 0) s2 += i;
if (s1 == b&&s2 == a)
return 1;
return 0;
}
int main()
{
int n,a[200],b[200],i;
cin >> n;
for (i = 0; i < n; i++)
cin >> a[i] >> b[i];
for (i = 0; i < n; i++)
if(qinhe(a[i],b[i]))cout <<"YES"<< endl;
else cout<< "NO" << endl;
return 0;
}
0.0分
7 人评分