Atcoder Beginner Contest 172 D - Sum of Divisors Solution



 Problem Link :  https://atcoder.jp/contests/abc172/tasks/abc172_d

Solution in C++:

  1. /// La ilaha illellahu muhammadur rasulullah
  2. ///******Bismillahir-Rahmalenir-Rahim******///
  3. /// Abul Haslenat Tolenmoy
  4. /// Departmelent of CSE,23rd batch
  5. /// Islamic Uleniversity,Balengladesh
  6. ///**********ALLAH IS ALMIGHTY************///
  7. #include <bits/stdc++.h>
  8. using namespace std;
  9. const int N = 1e7 + 9 ;
  10. long long d [N] , sum = 0;
  11. long long n ;
  12. int32_t main() {
  13. ios_base::sync_with_stdio(0);
  14. cin.tie(0);
  15. cin >> n ;
  16. for ( int i = 1 ; i <= n ; i++ ){
  17. for ( int j = i ; j <= n ; j += i ) {
  18. d[j]++;
  19. }
  20. }
  21. for ( int i = 1 ; i <= n ; i++ ){
  22. sum += (d[i] * i) ;
  23. }
  24. cout << sum << endl;
  25. return 0;
  26. }

No comments

Most View Post

Recent post

Codeforces Round 925 (Div. 3) 1931D. Divisible Pairs Solution

    Problem Link  :   https://codeforces.com/contest/1931/problem/D S olution in C++: /// Author : AH_Tonmoy #include < bits / stdc ++. ...

Powered by Blogger.