#include <iostream> int divisorsSum( int x ) { int result = 1; int upperLimit = x / 2 + 1; for ( int d = 2; d < upperLimit; ++d ) { if ( x % d == 0 ) { result += d; result += (x / d); upperLimit = (x / d); } } return result; } void findNFriends( int n ) { int findedCount = 0; for ( int f = 220; ; ++f ) { int s = divisorsSum( f ); if ( (f < s) && (f % 2 == s % 2) && (f == divisorsSum( s )) ) { ++findedCount; std::cout << "(" << f << ", " << s << ")" << std::endl; if ( findedCount >= n ) break; } } } int main() { findNFriends(14); return 0; }
Standard input is empty
(220, 284) (1184, 1210) (2620, 2924) (5020, 5564) (6232, 6368) (10744, 10856) (12285, 14595) (17296, 18416) (63020, 76084) (66928, 66992) (67095, 71145) (69615, 87633) (79750, 88730) (100485, 124155)