結果

問題 No.782 マイナス進数
ユーザー GrenacheGrenache
提出日時 2019-05-01 23:00:43
言語 Java21
(openjdk 21)
結果
AC  
実行時間 347 ms / 2,000 ms
コード長 890 bytes
コンパイル時間 3,489 ms
コンパイル使用メモリ 72,604 KB
実行使用メモリ 61,088 KB
最終ジャッジ日時 2023-08-30 04:29:47
合計ジャッジ時間 15,400 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 129 ms
55,900 KB
testcase_01 AC 129 ms
55,760 KB
testcase_02 AC 300 ms
60,728 KB
testcase_03 AC 309 ms
60,548 KB
testcase_04 AC 314 ms
60,336 KB
testcase_05 AC 297 ms
60,392 KB
testcase_06 AC 306 ms
60,680 KB
testcase_07 AC 303 ms
60,400 KB
testcase_08 AC 309 ms
61,088 KB
testcase_09 AC 305 ms
60,352 KB
testcase_10 AC 291 ms
60,144 KB
testcase_11 AC 316 ms
60,240 KB
testcase_12 AC 323 ms
60,124 KB
testcase_13 AC 340 ms
60,480 KB
testcase_14 AC 323 ms
60,068 KB
testcase_15 AC 321 ms
60,076 KB
testcase_16 AC 319 ms
60,272 KB
testcase_17 AC 345 ms
60,912 KB
testcase_18 AC 320 ms
60,684 KB
testcase_19 AC 328 ms
60,228 KB
testcase_20 AC 325 ms
60,256 KB
testcase_21 AC 333 ms
60,648 KB
testcase_22 AC 324 ms
60,472 KB
testcase_23 AC 320 ms
60,352 KB
testcase_24 AC 347 ms
60,576 KB
testcase_25 AC 322 ms
60,128 KB
testcase_26 AC 335 ms
60,512 KB
testcase_27 AC 332 ms
60,108 KB
testcase_28 AC 319 ms
60,164 KB
testcase_29 AC 134 ms
56,056 KB
testcase_30 AC 135 ms
56,012 KB
testcase_31 AC 140 ms
55,948 KB
testcase_32 AC 141 ms
55,752 KB
testcase_33 AC 133 ms
55,888 KB
testcase_34 AC 135 ms
55,584 KB
testcase_35 AC 139 ms
55,500 KB
testcase_36 AC 135 ms
56,088 KB
testcase_37 AC 138 ms
55,852 KB
権限があれば一括ダウンロードができます

ソースコード

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