結果

問題 No.1146 土偶Ⅰ
ユーザー Theta
提出日時 2022-10-25 16:40:10
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 452 ms / 2,000 ms
コード長 681 bytes
コンパイル時間 85 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 10,880 KB
最終ジャッジ日時 2024-07-03 15:01:38
合計ジャッジ時間 4,711 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 20
権限があれば一括ダウンロードができます

ソースコード

diff #

from itertools import combinations


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 main():
    dogu = []
    N = int(input())
    for _ in range(N):
        dogu.append(int(input()))

    ctr = 0
    for dogu1, dogu2, dogu3 in combinations(dogu, 3):
        if gcd(dogu1, dogu2, dogu3) == 1:
            ctr += 1

    print(ctr)


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