forked from ndb796/python-for-coding-test
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path6.java
More file actions
30 lines (24 loc) ยท 833 Bytes
/
6.java
File metadata and controls
30 lines (24 loc) ยท 833 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
28
29
30
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
// N, K๋ฅผ ๊ณต๋ฐฑ์ ๊ธฐ์ค์ผ๋ก ๊ตฌ๋ถํ์ฌ ์
๋ ฅ ๋ฐ๊ธฐ
int n = sc.nextInt();
int k = sc.nextInt();
int result = 0;
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);
System.out.println(result);
}
}