#include<stdio.h>
int main()
{
int a, b, sum_a, sum_b;
// 探索範囲
for(a = 2; a <= 1500; a++){
sum_a = 0;
// a の約数の合計を計算
for(int i = 1; i < a; i++){
if(a % i == 0)
sum_a += i;
}
b = sum_a; // b は a の約数の合計
// b の約数の合計を計算
sum_b = 0;
for(int j = 1; j < b; j++){
if(b % j == 0)
sum_b += j;
}
// 友愛数の条件を満たすか確認
if(a < b && sum_b == a){ // a < b による重複排除
printf("%d と %d は友愛数です。\n", a
, b
); }
}
return 0;
}
I2luY2x1ZGU8c3RkaW8uaD4KCmludCBtYWluKCkKewogICAgaW50IGEsIGIsIHN1bV9hLCBzdW1fYjsKCiAgICAvLyDmjqLntKLnr4Tlm7IKICAgIGZvcihhID0gMjsgYSA8PSAxNTAwOyBhKyspewogICAgICAgIHN1bV9hID0gMDsKCiAgICAgICAgLy8gYSDjga7ntITmlbDjga7lkIjoqIjjgpLoqIjnrpcKICAgICAgICBmb3IoaW50IGkgPSAxOyBpIDwgYTsgaSsrKXsKICAgICAgICAgICAgaWYoYSAlIGkgPT0gMCkKICAgICAgICAgICAgICAgIHN1bV9hICs9IGk7CiAgICAgICAgfQoKICAgICAgICBiID0gc3VtX2E7IC8vIGIg44GvIGEg44Gu57SE5pWw44Gu5ZCI6KiICgogICAgICAgIC8vIGIg44Gu57SE5pWw44Gu5ZCI6KiI44KS6KiI566XCiAgICAgICAgc3VtX2IgPSAwOwogICAgICAgIGZvcihpbnQgaiA9IDE7IGogPCBiOyBqKyspewogICAgICAgICAgICBpZihiICUgaiA9PSAwKQogICAgICAgICAgICAgICAgc3VtX2IgKz0gajsKICAgICAgICB9CgogICAgICAgIC8vIOWPi+aEm+aVsOOBruadoeS7tuOCkua6gOOBn+OBmeOBi+eiuuiqjQogICAgICAgIGlmKGEgPCBiICYmIHN1bV9iID09IGEpeyAvLyBhIDwgYiDjgavjgojjgovph43opIfmjpLpmaQKICAgICAgICAgICAgcHJpbnRmKCIlZCDjgaggJWQg44Gv5Y+L5oSb5pWw44Gn44GZ44CCXG4iLCBhLCBiKTsKICAgICAgICB9CiAgICB9CgogICAgcmV0dXJuIDA7Cn0K