結果

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

ソースコード

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;
			}

			if (ans.length() == 0) {
				pr.println(0);
			} else {
				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