結果

問題 No.1152 10億ゲーム
ユーザー ks2mks2m
提出日時 2020-08-07 22:45:40
言語 Java19
(openjdk 21)
結果
RE  
実行時間 -
コード長 1,793 bytes
コンパイル時間 3,361 ms
コンパイル使用メモリ 76,744 KB
実行使用メモリ 76,196 KB
平均クエリ数 14.68
最終ジャッジ日時 2023-09-24 04:49:35
合計ジャッジ時間 14,488 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 171 ms
71,744 KB
testcase_01 AC 162 ms
71,880 KB
testcase_02 RE -
testcase_03 RE -
testcase_04 AC 160 ms
71,352 KB
testcase_05 RE -
testcase_06 RE -
testcase_07 RE -
testcase_08 AC 169 ms
72,136 KB
testcase_09 AC 160 ms
70,172 KB
testcase_10 AC 162 ms
71,812 KB
testcase_11 AC 172 ms
71,748 KB
testcase_12 RE -
testcase_13 RE -
testcase_14 AC 176 ms
72,188 KB
testcase_15 AC 176 ms
70,140 KB
testcase_16 AC 162 ms
71,640 KB
testcase_17 AC 184 ms
71,772 KB
testcase_18 RE -
testcase_19 RE -
testcase_20 AC 160 ms
72,392 KB
testcase_21 AC 161 ms
71,580 KB
testcase_22 AC 167 ms
72,444 KB
testcase_23 AC 171 ms
71,592 KB
testcase_24 RE -
testcase_25 RE -
testcase_26 RE -
testcase_27 RE -
testcase_28 RE -
testcase_29 RE -
testcase_30 RE -
testcase_31 RE -
testcase_32 RE -
testcase_33 RE -
testcase_34 RE -
testcase_35 RE -
testcase_36 RE -
testcase_37 RE -
testcase_38 AC 169 ms
72,036 KB
testcase_39 AC 170 ms
72,396 KB
testcase_40 AC 174 ms
71,972 KB
testcase_41 AC 173 ms
71,296 KB
testcase_42 RE -
testcase_43 RE -
testcase_44 RE -
testcase_45 RE -
testcase_46 AC 169 ms
71,520 KB
testcase_47 AC 170 ms
72,076 KB
testcase_48 AC 162 ms
69,968 KB
testcase_49 AC 166 ms
71,980 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int x = sc.nextInt();
		int y = sc.nextInt();

		Map<Integer, Integer> mapx = bunkai(x);
		int x2 = mapx.getOrDefault(2, 0);
		int x5 = mapx.getOrDefault(5, 0);
		Map<Integer, Integer> mapy = bunkai(y);
		int y2 = mapy.getOrDefault(2, 0);
		int y5 = mapy.getOrDefault(5, 0);

		for (int i = 0; i < 35; i++) {
			if (x2 < y2) {
				x2++;
			} else if (x5 < y5) {
				x5++;
			} else if ((x2 + x5 - y2 - y5) % 2 == 0) {
				if (x2 < 7) {
					x2++;
				} else {
					x5++;
				}
			} else {
				if (x2 - y2 > x5 - y5) {
					x2--;
				} else {
					x5--;
				}
			}
			x = calc(x2, x5);
			System.out.println(x);
			if (x == y) {
				break;
			}
			mapx = bunkai(x);
			x2 = mapx.getOrDefault(2, 0);
			x5 = mapx.getOrDefault(5, 0);

			y = sc.nextInt();
			if (x == y) {
				break;
			}
			mapy = bunkai(y);
			y2 = mapy.getOrDefault(2, 0);
			y5 = mapy.getOrDefault(5, 0);
		}
		sc.close();
	}

	static int calc(int x2, int x5) {
		return Math.min(power(2, x2) * power(5, x5), 1000000000);
	}

	static int power(int x, int n) {
		if (n == 0) {
			return 1;
		}
		int val = power(x, n / 2);
		val = val * val;
		if (n % 2 == 1) {
			val = val * x;
		}
		return val;
	}

	static Map<Integer, Integer> bunkai(int n) {
		Map<Integer, Integer> soinsu = new HashMap<>();
		int end = (int) Math.sqrt(n);
		int d = 2;
		while (n > 1) {
			if (n % d == 0) {
				n /= d;
				if (soinsu.containsKey(d)) {
					soinsu.put(d, soinsu.get(d) + 1);
				} else {
					soinsu.put(d, 1);
				}
				end = (int) Math.sqrt(n);
			} else {
				if (d > end) {
					d = n - 1;
				}
				d++;
			}
		}
		return soinsu;
	}
}
0