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 숫자 의 모든 합이 정답
'알고리즘' 카테고리의 다른 글
C++ 알고리즘 - 백준 2309 일곱 난쟁이 (0) | 2025.01.19 |
---|---|
C++ 알고리즘 - 백준 6588 골드바흐의 추측 (0) | 2025.01.19 |
C++ 알고리즘 - 백준 4375 1 (모듈러 연산 원칙 관련) (0) | 2025.01.19 |
C++ 알고리즘 - 백준 24060 알고리즘 수업 - 병합 정렬 1 (0) | 2025.01.17 |
C++ 알고리즘 - 백준 25501 재귀의 귀재 (참조자 문자열) (0) | 2025.01.17 |