結果

問題 No.782 マイナス進数
ユーザー Grenache
提出日時 2019-05-01 22:58:23
言語 Java
(openjdk 23)
結果
WA  
実行時間 -
コード長 828 bytes
コンパイル時間 3,621 ms
コンパイル使用メモリ 75,360 KB
実行使用メモリ 59,272 KB
最終ジャッジ日時 2024-12-31 12:43:05
合計ジャッジ時間 15,730 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 27 WA * 9
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.*;
import java.util.Scanner;

public class Main_yukicoder782 {

	private static Scanner sc;
	private static Printer pr;

	private static void solve() {
		int t = sc.nextInt();
		int b = sc.nextInt();
		
		for (int tcase = 0; tcase < t; tcase++) {
			int n = sc.nextInt();
			
			StringBuilder ans = new StringBuilder();
			while (n != 0) {
				int mod = n % b;
				if (mod < 0) {
					mod -= b;
				}
				ans.append(mod);
				n = (n - mod) / b;
			}
			
			pr.println(ans.reverse().toString());
		}
	}

	// ---------------------------------------------------
	public static void main(String[] args) {
		sc = new Scanner(System.in);
		pr = new Printer(System.out);
			
		solve();
			
		pr.close();
		sc.close();
	}

	static class Printer extends PrintWriter {
		Printer(OutputStream out) {
			super(out);
		}
	}
}
0