1140 - 亲密数对
237
2
#include <iostream>
using namespace std;
//定义函数,求一个数的因数之和(不含1和它本身)
int yinzi(int x ) {
int i, c = 0;
for(i = 2; i * i <= x; i++) {
if(x % i == 0) {
if(x / i != i) {
c = c + i + x / i;
} else {
c = c + i;
}
}
}
return c;
}
int main() {
int n;
cin >> n;
//遍历M
for (int i = 2; i < n; i++) {
//遍历N
for (int j = 2; j < n; j++) {
//条件判断
if(i != j) {
if(yinzi(i) == j and yinzi(j) == i) {
cout << i << " " << j << endl;
}
}
}
}
}