結果

問題 No.316 もっと刺激的なFizzBuzzをください
ユーザー Theta
提出日時 2022-10-24 15:35:25
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 32 ms / 1,000 ms
コード長 837 bytes
コンパイル時間 89 ms
コンパイル使用メモリ 12,544 KB
実行使用メモリ 10,880 KB
最終ジャッジ日時 2024-07-02 17:58:19
合計ジャッジ時間 2,568 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 33
権限があれば一括ダウンロードができます

ソースコード

diff #


def gcd(*numbers: int) -> int:
    if len(numbers) == 1:
        return numbers[0]
    if len(numbers) == 2:
        a, b = numbers
        if a < b:
            a, b = b, a

        while True:

            if a % b == 0:
                return b
            a, b = b, a % b

    first_gcd = gcd(*numbers[:2])
    return gcd(first_gcd, *numbers[2:])


def lcm(*numbers: int) -> int:
    if len(numbers) == 1:
        return numbers[0]
    if len(numbers) == 2:
        return numbers[0] * numbers[1] // gcd(*numbers)
    first_lcm = lcm(*numbers[:2])
    return lcm(first_lcm, *numbers[2:])


def main():
    N = int(input())
    a, b, c = map(int, input().split())

    print(N // a + N // b + N // c
          - N // lcm(a, b) - N // lcm(b, c) - N // lcm(c, a)
          + N // lcm(a, b, c))


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