148A - Insomnia cure

发布时间 2023-09-02 05:30:57作者: 是可爱长大的

A. Insomnia cure

https://codeforces.com/problemset/problem/148/A

«One dragon. Two dragon. Three dragon», — the princess was counting. She had trouble falling asleep, and she got bored of counting lambs when she was nine.
However, just counting dragons was boring as well, so she entertained herself at best she could. Tonight she imagined that all dragons were here to steal her, and she was fighting them off. Every k-th dragon got punched in the face with a frying pan. Every l-th dragon got his tail shut into the balcony door. Every m-th dragon got his paws trampled with sharp heels. Finally, she threatened every n-th dragon to call her mom, and he withdrew in panic.
How many imaginary dragons suffered moral or physical damage tonight, if the princess counted a total of d dragons?

Input

Input data contains integer numbers k, l, m, n and d, each number in a separate line (1 ≤ k, l, m, n ≤ 10, 1 ≤ d ≤ 105).

Output

Output the number of damaged dragons.

alist = [] * 5
for i in range(5):
    alist.append(int(input()))
k, li, m, n, d = alist
alist = [i for i in range(1, d + 1)]
ans = 0
for value in alist:
    if value % k == 0:
        ans += 1
    elif value % li == 0:
        ans += 1
    elif value % m == 0:
        ans += 1
    elif value % n == 0:
        ans += 1

if ans <= d:
    print(ans)
else:
    print(d)

分析:

坏公主VS宝贝龙,没有判断累加就可以,边界条件是ans不要超过了d的数量