Advertisement
bartekltg

divisors pairs

Feb 6th, 2024 (edited)
1,040
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.20 KB | None | 0 0
  1. void foo (int n){
  2.     vector <int>largest_divisor(n,0);
  3.     vector <int> n_divisor(n,0);//number of divisors
  4.     largest_divisor[1]=1;
  5.     for (int i=2; i<n; i++){ //sieve
  6.         if (largest_divisor[i]==0){
  7.             for (int j=i; j<n; j+=i )
  8.                 largest_divisor[j]=i;
  9.         }
  10.     }
  11.  
  12.     n_divisor[1]=1;
  13.     for (int i=2; i<n; i++){
  14.         int p=largest_divisor[i];
  15.         int pk=1; // p^k in k-th inner iteration
  16.         int div=1; //number of divisors of p^k
  17.         int m=i;
  18.         do{
  19.             pk*=p;
  20.             div+=pk;
  21.             m/=p;
  22.         }while (m%p==0);
  23.         n_divisor[i] = div * n_divisor[m];
  24.     }
  25.  
  26.     auto f = [&](int x) { return n_divisor[x]-x -1; }; //number of proper divisors-1
  27.    
  28.     //look for solutions
  29.     for (int i=2; i<n; i++){
  30.         if ( f(i)<=i ){
  31.             if  (f(f(i))==i){
  32.                 cout << i << " "<<f(i) <<endl;
  33.             }
  34.         }
  35.     }
  36.  
  37. }
  38.  
  39.  
  40. /* results < 100'000'000
  41. 75 48        
  42. 195 140      
  43. 1648 1575    
  44. 1925 1050    
  45. 2295 2024    
  46. 6128 5775    
  47. 16587 8892  
  48. 20735 9504  
  49. 75495 62744  
  50. 206504 186615
  51. 219975 196664
  52. 309135 199760
  53. 507759 266000
  54. 544784 526575
  55. 549219 312620
  56. 817479 573560
  57. 1057595 587460
  58. 1159095 1139144
  59. 1331967 1081184
  60. 1341495 1173704
  61. 1348935 1208504
  62. 1459143 1236536
  63. 1524831 1233056
  64. 1763019 1140020
  65. 1902215 1000824
  66. 2142945 2102750
  67. 2226014 1921185
  68. 2421704 2140215
  69. 2576945 1279950
  70. 2681019 2036420
  71. 3010215 2312024
  72. 3123735 2198504
  73. 3220119 2171240
  74. 3676491 2958500
  75. 4282215 4012184
  76. 5644415 2580864
  77. 6446325 5088650
  78. 7509159 5416280
  79. 7890575 4311024
  80. 9345903 6081680
  81. 10106504 9247095
  82. 10925915 7460004
  83. 12251679 6618080
  84. 12900734 12500865
  85. 13693959 8713880
  86. 16247745 12146750
  87. 16381925 7875450
  88. 18845855 8829792
  89. 26502315 22559060
  90. 26525415 23379224
  91. 27862695 27735704
  92. 28206815 14371104
  93. 31213899 13922100
  94. 31356314 23939685
  95. 32014575 28219664
  96. 37291625 22013334
  97. 41950359 26409320
  98. 42125144 40818855
  99. 43321095 34093304
  100. 52389315 49217084
  101. 58354119 33299000
  102. 69090615 66086504
  103. 70112175 64045904
  104. 80870615 37324584
  105. 84854315 41137620
  106. 85141719 52026920
  107. 87689415 66275384
  108. 87802407 76011992
  109. 88567059 61423340
  110. 93423519 62252000
  111. 96751395 94970204
  112. 97389039 52601360
  113. 99735705 93993830
  114. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement