結果

問題 No.546 オンリー・ワン
ユーザー sue_charosue_charo
提出日時 2017-07-15 00:16:30
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 39 ms / 2,000 ms
コード長 1,533 bytes
コンパイル時間 80 ms
コンパイル使用メモリ 12,800 KB
実行使用メモリ 11,648 KB
最終ジャッジ日時 2024-04-16 20:53:04
合計ジャッジ時間 1,019 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 39 ms
11,520 KB
testcase_01 AC 39 ms
11,520 KB
testcase_02 AC 36 ms
11,520 KB
testcase_03 AC 36 ms
11,520 KB
testcase_04 AC 37 ms
11,648 KB
testcase_05 AC 32 ms
11,648 KB
testcase_06 AC 33 ms
11,520 KB
testcase_07 AC 35 ms
11,520 KB
testcase_08 AC 36 ms
11,520 KB
testcase_09 AC 39 ms
11,520 KB
testcase_10 AC 38 ms
11,520 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

# coding: utf-8
import array, bisect, collections, copy, heapq, itertools, math, random, re, string, sys, time
sys.setrecursionlimit(10 ** 7)
INF = 10 ** 20
MOD = 10 ** 9 + 7


def II(): return int(input())
def ILI(): return list(map(int, input().split()))
def IAI(LINE): return [ILI() for __ in range(LINE)]
def IDI(): return {key: value for key, value in ILI()}


def read():
    N, L, H = ILI()
    C = ILI()
    return N, L, H, C


def calc_div(low, high, div_num):
    low_div, low_mod = divmod(low, div_num)
    high_div = high // div_num
    if low_mod != 0:
        low_div += 1

    return high_div - low_div + 1


def gcd(a, b):
    while b:
        a, b = b, a % b
    return a


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


def l_lcm(list):
    if len(list) == 0:
        return 0
    elif len(list) == 1:
        return list[0]
    elif len(list) == 2:
        return lcm(list[0], list[1])
    else:
        ret_lcm = lcm(list[0], list[1])
        for i in range(2, len(list)):
            ret_lcm = lcm(ret_lcm, list[i])
        return ret_lcm


def solve(N, L, H, C):
    ans = 0
    comb_num = [1, -2, 3, -4, 5, -6, 7, -8, 9, -10]
    for i in range(1, N + 1):
        sum_div_num = 0
        for comb in itertools.combinations(C, i):
            comb_lcm = l_lcm(comb)
            div_num = calc_div(L, H, comb_lcm)
            sum_div_num += div_num

        ans += sum_div_num * comb_num[i - 1]

    return ans


def main():
    params = read()
    print(solve(*params))


if __name__ == "__main__":
    main()
0