結果

問題 No.546 オンリー・ワン
ユーザー OttyLabOttyLab
提出日時 2021-07-14 22:45:15
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 95 ms / 2,000 ms
コード長 679 bytes
コンパイル時間 952 ms
コンパイル使用メモリ 86,976 KB
実行使用メモリ 77,956 KB
最終ジャッジ日時 2023-09-17 01:12:07
合計ジャッジ時間 2,625 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 76 ms
71,516 KB
testcase_01 AC 75 ms
71,536 KB
testcase_02 AC 76 ms
71,388 KB
testcase_03 AC 75 ms
71,368 KB
testcase_04 AC 75 ms
71,356 KB
testcase_05 AC 76 ms
71,724 KB
testcase_06 AC 76 ms
71,772 KB
testcase_07 AC 84 ms
76,668 KB
testcase_08 AC 95 ms
77,400 KB
testcase_09 AC 95 ms
77,572 KB
testcase_10 AC 95 ms
77,956 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import math
from collections import deque

N, L, H = map(int, input().split())
C = list(map(int, input().split()))

def calc(n):
    ret = deque()
    cnt = 0
    while n > 0:
        if n & 1:
            ret.append(C[cnt])
        n >>= 1
        cnt += 1
    return ret

ans = 0
for i in range(1, 1 << N):
    d = calc(i)
    num = len(d)
    if num == 1:
        v = d.pop()
        ans += H // v - (L-1) // v
        continue

    while len(d) > 1:
        v1 = d.pop()
        v2 = d.pop()
        d.append(v1*v2//math.gcd(v1,v2))
    v = d.pop()
    if num % 2 == 1:
        ans += (H // v - (L-1) // v)*num
    else:
        ans -= (H // v - (L-1) // v)*num

print(ans)

0