結果

問題 No.546 オンリー・ワン
ユーザー convexineqconvexineq
提出日時 2021-02-15 01:28:37
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 86 ms / 2,000 ms
コード長 546 bytes
コンパイル時間 669 ms
コンパイル使用メモリ 86,740 KB
実行使用メモリ 76,440 KB
最終ジャッジ日時 2023-09-29 19:13:33
合計ジャッジ時間 2,157 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 73 ms
71,464 KB
testcase_01 AC 72 ms
71,352 KB
testcase_02 AC 74 ms
71,360 KB
testcase_03 AC 73 ms
71,660 KB
testcase_04 AC 75 ms
71,140 KB
testcase_05 AC 73 ms
71,392 KB
testcase_06 AC 79 ms
75,764 KB
testcase_07 AC 79 ms
75,672 KB
testcase_08 AC 80 ms
75,376 KB
testcase_09 AC 86 ms
76,440 KB
testcase_10 AC 79 ms
75,672 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from math import gcd
def lcm(x,y): return x//gcd(x,y)*y

def mobius_to_low(res,n):
    for i in range(n):
        i = 1<<i
        for j in range(1<<n):
            if j&i == 0: res[j] -= res[j^i]

n,L,R = map(int,input().split())
*a, = map(int,input().split())

def f(X,n):
    if X==0: return 0
    N = 1<<n
    yaku = [1]*N
    for i in range(n):
        for j in range(1<<i):
            yaku[j+(1<<i)] = lcm(yaku[j], a[i])

    r = [X//y for y in yaku]
    mobius_to_low(r,n)
    return sum(r[1<<i] for i in range(n))

print(f(R,n)-f(L-1,n))
0