結果

問題 No.1352 Three Coins
ユーザー lam6er
提出日時 2025-04-15 22:06:59
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 394 ms / 2,000 ms
コード長 1,093 bytes
コンパイル時間 927 ms
コンパイル使用メモリ 81,772 KB
実行使用メモリ 235,468 KB
最終ジャッジ日時 2025-04-15 22:08:41
合計ジャッジ時間 3,969 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 34
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
import math

def main():
    A, B, C = map(int, sys.stdin.readline().split())
    a, b, c = A, B, C

    # Compute gcd of three numbers
    d = math.gcd(math.gcd(a, b), c)
    if d != 1:
        print("INF")
        return

    m = min(a, b, c)
    reachable = {0}
    current_max = 0
    current_streak = 0
    required_streak = m
    i = 1

    while True:
        if (i - a in reachable) or (i - b in reachable) or (i - c in reachable):
            reachable.add(i)
            if i == current_max + 1:
                current_streak += 1
                current_max = i
                if current_streak == required_streak:
                    break
            else:
                current_streak = 1
                current_max = i
                if current_streak == required_streak:
                    break
        else:
            current_streak = 0
        i += 1

    upper_limit = current_max - m
    count = 0
    for num in range(1, upper_limit + 1):
        if num not in reachable:
            count += 1

    print(count)

if __name__ == "__main__":
    main()
0