Advertisement
MadCortez

Untitled

Nov 10th, 2020
177
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.67 KB | None | 0 0
  1. #include <iostream>
  2. #include <time.h>
  3. int main()
  4. {
  5.     const int N = 1000000;
  6.     int* arr = new int[N + 1];
  7.  
  8.     double start = clock() * 1.0 / CLOCKS_PER_SEC;
  9.  
  10.     for (int i = 0; i <= N; i++)
  11.     {
  12.         arr[i] = 0;
  13.     }
  14.  
  15.  
  16.     for (int i = 1; i <= N; i++)
  17.     {
  18.  
  19.         for (int j = i + i; j <= N; j += i)
  20.             arr[j] += i;
  21.     }
  22.     for (int i = 1; i <= N; i++)
  23.     {
  24.         if (arr[i] <= N && arr[i] != i && arr[arr[i]] == i)
  25.             std::cout << arr[i] << "  " << i << std::endl;
  26.  
  27.     }
  28.  
  29.  
  30.     delete[]arr;
  31.  
  32.     double end = clock() * 1.0 / CLOCKS_PER_SEC;
  33.     std::cout << end - start << "sec" << std::endl;
  34.  
  35.     return 0;
  36.  
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement