Advertisement
momo2345

sum of divisors

Nov 2nd, 2020
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.73 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. typedef long long ll;
  4. #include <ext/pb_ds/assoc_container.hpp>
  5. using namespace __gnu_pbds;
  6. typedef tree<ll,null_type,less_equal<ll>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
  7. #define suni ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
  8. #define endl "\n"
  9. #define mn int main()
  10. #define frac() cout.unsetf(ios::floatfield);cout.precision(6);cout.setf(ios::fixed,ios::floatfield);
  11.  
  12. const int mx=1e7+123;
  13. int cnt[mx];
  14.  
  15.  
  16. mn
  17. {
  18.     suni;
  19.     int n; cin>>n;
  20.     ll sum=0;
  21.     for(int i=1;i<=n;i++){
  22.         for(int j=i;j<=n;j+=i)
  23.             cnt[j]++;
  24.         }
  25.         for(int i=1;i<=n;i++){
  26.             sum+= (1LL*i*cnt[i]);
  27.         }
  28.     cout<<sum<<endl;
  29.  
  30.  
  31. }
  32.  
  33.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement