結果

問題 No.1152 10億ゲーム
ユーザー ks2m
提出日時 2020-08-07 23:24:55
言語 Java
(openjdk 23)
結果
AC  
実行時間 246 ms / 2,000 ms
コード長 1,866 bytes
コンパイル時間 2,398 ms
コンパイル使用メモリ 79,572 KB
実行使用メモリ 70,840 KB
平均クエリ数 22.70
最終ジャッジ日時 2024-07-17 05:19:27
合計ジャッジ時間 16,721 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 50
権限があれば一括ダウンロードができます

ソースコード

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 + x5 - y2 - y5) % 2 == 0) {
if (x5 < y5) {
x5++;
} else if (x2 < 7) {
x2++;
} else if (x2 > 7) {
x2--;
} else {
x5++;
}
} else if (x5 < y5) {
x5++;
} else if (x2 < y2) {
x2++;
} 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;
}
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0