Imran_Mohammed

Divisor__harmonic series(prime)

Feb 9th, 2021 (edited)
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.58 KB | None | 0 0
  1. // In The Name Of Allah
  2.  
  3. #include<bits/stdc++.h>
  4. using namespace std;
  5.  
  6. const int mx = 1e6+123;
  7. vector<int> divisor [mx];
  8.  
  9. int main(){
  10.  
  11.     //Number of divisor(1 to n):
  12.     //Harmonic Series: complexity n ln(n)
  13.  
  14.     int n;
  15.     cin >> n;//5
  16.  
  17.     for(int i=1; i<=n; i++){
  18.        for(int j=i; j<=n; j +=i){
  19.           divisor[j].push_back(i);
  20.        }
  21.     }
  22.  
  23.     for(int i=1; i<=n; i++){
  24.             cout << i << " : ";
  25.        for(auto u : divisor[i]) cout << u << " ";
  26.        cout << endl;
  27.     }
  28.  /*1 : 1
  29.    2 : 1 2
  30.    3 : 1 3
  31.    4 : 1 2 4
  32.    5 : 1 5*/
  33.  
  34.  return 0;
  35. }
  36.  
Add Comment
Please, Sign In to add comment