#include <iostream> using namespace std; int sum_of_dil(int n) { int sum = 0; if (n%2==0) { for(int i=1;i<=n/2;++i) if (n%i ==0) sum += i; } else { for(int i=1;i<=n/2;i+=2) if (n%i ==0) sum += i; } return sum; } int main() { int a, b; int count = 0; cin >> a >> b; for(int i=a;i<=b;++i) { for(int j=i+1;j<=b;++j) { if (sum_of_dil(i) == j && sum_of_dil(j) == i) { cout << i << " " << j << endl; count++; } } } if (count ==0) cout << "Absent" << endl; return 0; } Task from here -> Tyk
Two different positive integers are called friendly if the first one is equal to the sum of the divisors of the second number, except for the second number itself, and the second is equal to the sum of the divisors of the first number, except for the very first number. You need to find all pairs of friendly numbers, both of which belong to the interval from M to N.
Does not pass on time.