[白準11005]変換アレイ2

841 ワード

import java.util.Scanner;

public class 진법변환2 {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int b = sc.nextInt();
		int len = 0;//b진법한 수 길이
		int number=0;
		for(int i=0;i<n;i++) {
			if(Math.pow(b,i)>n) {
				len=i-1;
				break;
			}
		}
		StringBuilder sb = new StringBuilder();
		for(int i=len;i>=0;i--) {
			number = (int) (n/Math.pow(b,i));
			n = (int) (n-number*Math.pow(b,i));
			if(number>=10)
				sb.append((char)(number+55));
			else
				sb.append(number);
		}
		System.out.println(sb);
		
	}
}