Algorithm/백준
C++ 알고리즘 - 백준 17427 약수의 합 2
마루설아
2025. 1. 19. 17:29
https://www.acmicpc.net/problem/17427
#include <bits/stdc++.h>
#define endl "\n"
using namespace std;
void CPP_INIT() {
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
}
int main(void) {
CPP_INIT();
int input;
long long answer = 0;
cin >> input;
for (int i = 1; i <= input; i++) {
answer += (input / i) * i;
}
cout << answer << endl;
}
input = 10 일때,
1의 개수 = 10 (10/1)
2의 개수 = 5 (10/2)
3의 개수 = 3 (10/3)
4의 개수 = 2 (10/4)
...
개수 x 숫자 의 모든 합이 정답