fork(1) download
  1. #include <iostream>
  2.  
  3. int divisorsSum( int x )
  4. {
  5. int result = 1;
  6.  
  7. for ( int d = 2; d*d <= x; ++d )
  8. {
  9. if ( x % d == 0 )
  10. {
  11. result += d + x/d;
  12. }
  13. }
  14.  
  15. return result;
  16. }
  17.  
  18. void findNFriends( int n )
  19. {
  20. int findedCount = 0;
  21. for ( int f = 0; ; ++f )
  22. {
  23. int s = divisorsSum( f );
  24. if ( (f < s) && (f == divisorsSum( s )))
  25. {
  26. ++findedCount;
  27. std::cout << findedCount << ": (" << f << ", " << s << ")" << std::endl;
  28.  
  29. if ( findedCount >= n ) break;
  30. }
  31. }
  32. }
  33.  
  34. int main() {
  35. findNFriends(14);
  36. return 0;
  37. }
Success #stdin #stdout 0.54s 2724KB
stdin
Standard input is empty
stdout
1: (220, 284)
2: (1184, 1210)
3: (2620, 2924)
4: (5020, 5564)
5: (6232, 6368)
6: (10744, 10856)
7: (12285, 14595)
8: (17296, 18416)
9: (63020, 76084)
10: (66928, 66992)
11: (67095, 71145)
12: (69615, 87633)
13: (79750, 88730)
14: (100485, 124155)