fork download
  1. #include <iostream>
  2.  
  3. int divisorsSum( int x )
  4. {
  5. int result = 1;
  6. int upperLimit = x / 2 + 1;
  7.  
  8. for ( int d = 2; d < upperLimit; ++d )
  9. {
  10. if ( x % d == 0 )
  11. {
  12. result += d;
  13. result += (x / d);
  14. upperLimit = (x / d);
  15. }
  16. }
  17.  
  18. return result;
  19. }
  20.  
  21. void findNFriends( int n )
  22. {
  23. int findedCount = 0;
  24. for ( int f = 220; ; ++f )
  25. {
  26. int s = divisorsSum( f );
  27. if ( (f < s) && (f % 2 == s % 2) && (f == divisorsSum( s )) )
  28. {
  29. ++findedCount;
  30. std::cout << "(" << f << ", " << s << ")" << std::endl;
  31.  
  32. if ( findedCount >= n ) break;
  33. }
  34. }
  35. }
  36.  
  37. int main() {
  38. findNFriends(14);
  39. return 0;
  40. }
Success #stdin #stdout 11.85s 2724KB
stdin
Standard input is empty
stdout
(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)