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 971 (Div. 4) 2009C. The Legend of Freya the Frog Solution

  Problem Link    https://codeforces.com/contest/2009/problem/C S olution in C++: /// Author : AH_Tonmoy #include < bits / stdc ++. h &g...

Powered by Blogger.