Notice
Recent Posts
Recent Comments
Link
«   2025/07   »
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 31
Tags
more
Archives
Today
Total
관리 메뉴

forDevLife

[이코테]1이 될 때까지 <그리디> 본문

알고리즘

[이코테]1이 될 때까지 <그리디>

JH_Lucid 2021. 5. 3. 13:01
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer(br.readLine(), " ");

        int N = Integer.parseInt(st.nextToken());
        int K = Integer.parseInt(st.nextToken());

        int result = 0;
        while (N != 1) {
            if (N % K == 0) { //나누어 떨어지면,
                N = N / K;
                result++;
            } else {
                N -= 1;
                result++;
            }
        }
        System.out.println(result);
    }
}
Comments