結果

問題 No.546 オンリー・ワン
ユーザー freecss00freecss00
提出日時 2020-01-17 03:22:23
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 45 ms / 2,000 ms
コード長 641 bytes
コンパイル時間 403 ms
コンパイル使用メモリ 10,844 KB
実行使用メモリ 8,000 KB
最終ジャッジ日時 2023-09-07 04:02:59
合計ジャッジ時間 1,601 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 17 ms
7,996 KB
testcase_01 AC 17 ms
7,972 KB
testcase_02 AC 17 ms
7,912 KB
testcase_03 AC 17 ms
7,976 KB
testcase_04 AC 17 ms
8,000 KB
testcase_05 AC 17 ms
7,956 KB
testcase_06 AC 18 ms
7,892 KB
testcase_07 AC 22 ms
7,908 KB
testcase_08 AC 40 ms
8,000 KB
testcase_09 AC 43 ms
7,912 KB
testcase_10 AC 45 ms
7,996 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

# https://yukicoder.me/problems/no/546
import math

def lcm(a, b):
    return a * b // math.gcd(a, b)

n, l, h = map(int, input().split())
c = list(map(int, input().split()))

def count(l, r, div):
    if l % div == 0:
        l -= 1
    return r // div - l // div

ans = 0
for k in range(n):
    A = count(l, h, c[k])
    for i in range(1, 1<<n):
        bitcnt = bin(i).count('1')
        if not (i>>k & 1) or bitcnt == 1:
            continue
        x = 1
        for j in range(n):
            if i>>j & 1:
                x = lcm(x, c[j])
        m = 1 if bitcnt % 2 == 0 else -1
        A -= m * count(l, h, x)
    ans += A
print(ans)
0