Advertisement
sajid161

class-24(1)

Jan 8th, 2025
15
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.53 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. const int mx=1e7+123;
  4. #define optimize() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
  5. long long int cnt[mx];
  6. int main()
  7. {
  8. //This coding complexity is n ln n but their square root loop will take n sqrt(n);
  9. optimize();
  10. int n;
  11. cin>>n;
  12. for(int i=1;i<=n;i++)
  13. {
  14. for(int j=i;j<=n;j+=i)
  15. {
  16. cnt[j]++;
  17. }
  18. }
  19. long long int ans=0;
  20. for(int i=1;i<=n;i++)
  21. {
  22. ans+=(i*cnt[i]);
  23. }
  24. cout<<ans;
  25.  
  26. }
  27.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement