結果

問題 No.546 オンリー・ワン
ユーザー Ryushi-techRyushi-tech
提出日時 2020-06-20 20:08:11
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 949 bytes
コンパイル時間 90 ms
コンパイル使用メモリ 11,004 KB
実行使用メモリ 8,556 KB
最終ジャッジ日時 2023-09-16 17:43:30
合計ジャッジ時間 1,048 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
8,336 KB
testcase_01 AC 15 ms
8,496 KB
testcase_02 AC 15 ms
8,476 KB
testcase_03 AC 16 ms
8,340 KB
testcase_04 WA -
testcase_05 AC 14 ms
8,488 KB
testcase_06 AC 15 ms
8,492 KB
testcase_07 AC 17 ms
8,536 KB
testcase_08 AC 20 ms
8,348 KB
testcase_09 AC 21 ms
8,556 KB
testcase_10 AC 21 ms
8,356 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from math import gcd, ceil
import itertools as it
n, l, h = map(int, input().split())
A = list(map(int, input().split()))

G = [[] for _ in range(n + 1)]

if n == 1:
    print((h - l + 1) // A[0])
    exit()


def divc(x, y):
    return ceil(x // y)


for g in it.product([0, 1], repeat=n):
    gc = g.count(1)
    if gc == 0 or gc == 1:
        continue
    tmp = []
    for i, gg in enumerate(g):
        if gg:
            tmp.append(A[i])
    res = tmp[0]
    for j in range(1, gc):
        res = res * tmp[j] // gcd(res, tmp[j])
    G[gc].append(res)


def solve(z):
    ans = [[0] for _ in range(n + 1)]
    su = 0
    for a in A:
        su += divc(z,a)
    for i in range(1, n + 1):
        for gx in G[i]:
            ans[i][0] += divc(z, gx)
    for j, x in enumerate(ans):
        if any(j == c for c in [0, 1]):
            continue
        sign = j & 1
        su -= (-1)**sign * j * x[0]
    return su


print(solve(h) - solve(l - 1))
0