forked from ndb796/python-for-coding-test
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path6.cpp
More file actions
27 lines (22 loc) ยท 648 Bytes
/
6.cpp
File metadata and controls
27 lines (22 loc) ยท 648 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#include <bits/stdc++.h>
using namespace std;
int n, k;
int result;
int main() {
// N, K๋ฅผ ๊ณต๋ฐฑ์ ๊ธฐ์ค์ผ๋ก ๊ตฌ๋ถํ์ฌ ์
๋ ฅ ๋ฐ๊ธฐ
cin >> n >> k;
while (true) {
// N์ด K๋ก ๋๋์ด ๋จ์ด์ง๋ ์๊ฐ ๋ ๋๊น์ง๋ง 1์ฉ ๋นผ๊ธฐ
int target = (n / k) * k;
result += (n - target);
n = target;
// N์ด K๋ณด๋ค ์์ ๋ (๋ ์ด์ ๋๋ ์ ์์ ๋) ๋ฐ๋ณต๋ฌธ ํ์ถ
if (n < k) break;
// K๋ก ๋๋๊ธฐ
result += 1;
n /= k;
}
// ๋ง์ง๋ง์ผ๋ก ๋จ์ ์์ ๋ํ์ฌ 1์ฉ ๋นผ๊ธฐ
result += (n - 1);
cout << result << '\n';
}