結果

問題 No.546 オンリー・ワン
ユーザー H3PO4
提出日時 2020-09-22 11:50:28
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 35 ms / 2,000 ms
コード長 437 bytes
コンパイル時間 153 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 10,880 KB
最終ジャッジ日時 2024-06-25 23:07:48
合計ジャッジ時間 1,095 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 7
権限があれば一括ダウンロードができます

ソースコード

diff #

import itertools
from math import gcd
from functools import reduce

N, L, H = map(int, input().split())
A = tuple(map(int, input().split()))

lcm = lambda a, b: a * b // gcd(a, b)


def solve(X):
    """ 1~Xまで"""
    res = 0
    for i in range(1, N + 1):
        for t in itertools.combinations(A, i):
            l = reduce(lcm, t)
            res += (X // l) * i * (-1) ** (i - 1)
    return res


print(solve(H) - solve(L - 1))
0