結果

問題 No.316 もっと刺激的なFizzBuzzをください
ユーザー 🍡yurahuna🍡yurahuna
提出日時 2015-12-20 16:34:44
言語 Python2
(2.7.18)
結果
AC  
実行時間 23 ms / 1,000 ms
コード長 1,051 bytes
コンパイル時間 643 ms
コンパイル使用メモリ 6,672 KB
実行使用メモリ 7,860 KB
最終ジャッジ日時 2023-08-13 16:12:37
合計ジャッジ時間 2,974 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 22 ms
7,640 KB
testcase_01 AC 23 ms
7,748 KB
testcase_02 AC 22 ms
7,636 KB
testcase_03 AC 22 ms
7,644 KB
testcase_04 AC 22 ms
7,860 KB
testcase_05 AC 22 ms
7,840 KB
testcase_06 AC 22 ms
7,612 KB
testcase_07 AC 22 ms
7,816 KB
testcase_08 AC 22 ms
7,808 KB
testcase_09 AC 23 ms
7,636 KB
testcase_10 AC 22 ms
7,668 KB
testcase_11 AC 22 ms
7,800 KB
testcase_12 AC 22 ms
7,672 KB
testcase_13 AC 22 ms
7,812 KB
testcase_14 AC 22 ms
7,640 KB
testcase_15 AC 21 ms
7,636 KB
testcase_16 AC 22 ms
7,860 KB
testcase_17 AC 21 ms
7,672 KB
testcase_18 AC 22 ms
7,748 KB
testcase_19 AC 22 ms
7,748 KB
testcase_20 AC 22 ms
7,612 KB
testcase_21 AC 22 ms
7,668 KB
testcase_22 AC 22 ms
7,800 KB
testcase_23 AC 22 ms
7,756 KB
testcase_24 AC 22 ms
7,744 KB
testcase_25 AC 22 ms
7,808 KB
testcase_26 AC 22 ms
7,804 KB
testcase_27 AC 22 ms
7,648 KB
testcase_28 AC 22 ms
7,724 KB
testcase_29 AC 22 ms
7,748 KB
testcase_30 AC 22 ms
7,660 KB
testcase_31 AC 21 ms
7,804 KB
testcase_32 AC 21 ms
7,812 KB
testcase_33 AC 21 ms
7,660 KB
testcase_34 AC 22 ms
7,812 KB
testcase_35 AC 21 ms
7,812 KB
testcase_36 AC 22 ms
7,856 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#a, b, cがすべて異なるとき: 3つの集合の和集合
#n(AorBorC) = n(A)+n(B)+n(C)-n(A&B)-n(B&C)-n(C&A)+n(A&B&C)
#a, b, cのうちちょうど2つが等しいとき: 2つの集合の和集合
#a, b, cのどれもが等しいとき: n(a)
######## !!注意!! n(A&B):AとBの「最小公倍数」の倍数の数

from fractions import gcd

def lcm(numbers):
    return reduce(lambda x, y: (x*y)/gcd(x,y), numbers, 1)
    
N = input()
li = map(int, raw_input().split())
li_uniq = []    #重複を消す
for i in li:
    if not i in li_uniq:
        li_uniq.append(i)

if len(li_uniq) == 3:
    a = li_uniq[0]
    b = li_uniq[1]
    c = li_uniq[2]
    na = N/a
    nb = N/b
    nc = N/c
    nab = N/lcm([a, b])
    nbc = N/lcm([b, c])
    nca = N/lcm([c, a])
    nabc = N/lcm([a, b, c])
    print na+nb+nc-nab-nbc-nca+nabc
    #print na, nb, nc, nab, nbc, nca, nabc
elif len(li_uniq) == 2:
    a = li_uniq[0]
    b = li_uniq[1]
    na = N/a
    nb = N/b
    nab = N/lcm([a,b])
    print na+nb-nab
else:
    a = li_uniq[0]
    na = N/a
    print na
0