codeforces-148A-Insomnia cure

148A-Insomnia cure

                        Time Limit:2000MS     Memory Limit:262144KB 

Description
«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.

Input
1
2
3
4
12
Output
12

Input
2
3
4
5
24
Output
17

题目链接:cf-148A

题目大意:公主攻击龙,有k,l,m,n四种方式,编号为这四个数字的倍数的龙被攻击。总共有d(编号1~d)只龙。问被攻击到的数量

以下是代码:

#include <bits/stdc++.h>
using namespace std;
int main()
{
    int a, b, c, d, s;
    cin >> a >> b >> c >> d >> s;
    int q[100005]={0};
    for( int i=a ; i<=s ; i+=a ) q[i] = 1;
    for( int i=b ; i<=s ; i+=b ) q[i] = 1;
    for( int i=c ; i<=s ; i+=c ) q[i] = 1;
    for( int i=d ; i<=s ; i+=d ) q[i] = 1;
    int ans = 0;
    for( int i=1 ; i<=s ; i++ ) if( q[i] ) ans++;
    cout << ans << endl;
    return 0;
}

你可能感兴趣的:(CF,148A)