Advertisement
Imran_Mohammed

Sum of number of divisor

Mar 4th, 2021
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.59 KB | None | 0 0
  1. //In The Name Of Allah
  2. //Sum Of Number of Divisor :
  3. //Complexity : 0( sqrt(n) )
  4. //Total number of divisor : pow( n, 1/3 )
  5.  
  6. #include<bits/stdc++.h>
  7. using namespace std;
  8.  
  9. #define optimize() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
  10. #define endl '\n'
  11.  
  12. //create function
  13. int SNOD(int n){
  14.     int sq = sqrt(n);
  15.     int ret = 0;
  16.  
  17.     for(int i=1; i<=sq; i++){
  18.         ret += (n/i)-i;
  19.     }
  20.  
  21.     ret *= 2;
  22.     ret += sq;
  23.  
  24.     return ret;
  25. }
  26.  
  27. //main function
  28. int main()
  29. {
  30.     optimize()
  31.  
  32.     int n;
  33.     cin >> n;
  34.  
  35.     cout << SNOD(n) << endl;
  36.  
  37.     return 0;
  38. }
  39.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement