結果

問題 No.1152 10億ゲーム
ユーザー smallcopsesmallcopse
提出日時 2020-08-07 23:09:00
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 1,561 bytes
コンパイル時間 650 ms
コンパイル使用メモリ 11,024 KB
実行使用メモリ 24,572 KB
平均クエリ数 24.08
最終ジャッジ日時 2023-09-24 04:58:00
合計ジャッジ時間 6,507 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 72 ms
23,876 KB
testcase_01 AC 67 ms
24,108 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 AC 66 ms
23,888 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 AC 65 ms
23,616 KB
testcase_09 AC 65 ms
24,060 KB
testcase_10 AC 66 ms
24,104 KB
testcase_11 AC 65 ms
23,700 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 84 ms
24,560 KB
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 65 ms
23,856 KB
testcase_21 AC 68 ms
24,124 KB
testcase_22 AC 66 ms
24,164 KB
testcase_23 AC 68 ms
23,592 KB
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 AC 67 ms
24,192 KB
testcase_39 AC 67 ms
24,304 KB
testcase_40 AC 69 ms
24,084 KB
testcase_41 AC 68 ms
23,656 KB
testcase_42 WA -
testcase_43 WA -
testcase_44 WA -
testcase_45 WA -
testcase_46 AC 69 ms
23,724 KB
testcase_47 AC 68 ms
23,428 KB
testcase_48 AC 65 ms
24,156 KB
testcase_49 AC 67 ms
23,988 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

def main():
    x1, x2 = map(int, input().split())
    # 素因数分解して2の数と5の数を数える
    y1 = prime_factorize(x1)
    y2 = prime_factorize(x2)
    my_n2 = y1.count(2)
    my_n5 = y1.count(5)
    kiri_n2 = y2.count(2)
    kiri_n5 = y2.count(5)
    # print(y1, my_n2, my_n5)
    # print(y2, kiri_n2, kiri_n5)
    # 戦略: 2の数と5の数が相手と一致するように数を選んでいく
    turn = 1
    while x1 != x2 and turn <= 35:
        # 自分の番
        # 2の数の差と5の数の差のうち、差の大きいほうの差を小さくする
        if abs(my_n2 - kiri_n2) > abs(my_n5 - kiri_n5):
            if my_n2 < kiri_n2:
                my_n2 += 1
                x1 *= 2
            elif my_n2 > kiri_n2:
                my_n2 -= 1
                x1 = x1 // 2
        else:
            if my_n5 < kiri_n5:
                my_n5 += 1
                x1 *= 5
            elif my_n5 > kiri_n5:
                my_n5 -= 1
                x1 = x1 // 5
        
        print(x1, flush=True)
        # 一致したら終了
        if x1 == x2:
            return

        x2 = int(input())
        y2 = prime_factorize(x2)
        kiri_n2 = y2.count(2)
        kiri_n5 = y2.count(5)

        turn += 1
if __name__ == '__main__':
    main()
0