Atcoder Beginner Contest 172 D - Sum of Divisors Solution
Problem Link : https://atcoder.jp/contests/abc172/tasks/abc172_d
Solution in C++:
- /// La ilaha illellahu muhammadur rasulullah
- ///******Bismillahir-Rahmalenir-Rahim******///
- /// Abul Haslenat Tolenmoy
- /// Departmelent of CSE,23rd batch
- /// Islamic Uleniversity,Balengladesh
- ///**********ALLAH IS ALMIGHTY************///
- #include <bits/stdc++.h>
- using namespace std;
- const int N = 1e7 + 9 ;
- long long d [N] , sum = 0;
- long long n ;
- int32_t main() {
- ios_base::sync_with_stdio(0);
- cin.tie(0);
- cin >> n ;
- for ( int i = 1 ; i <= n ; i++ ){
- for ( int j = i ; j <= n ; j += i ) {
- d[j]++;
- }
- }
- for ( int i = 1 ; i <= n ; i++ ){
- sum += (d[i] * i) ;
- }
- cout << sum << endl;
- return 0;
- }
No comments