No.316 Give Me a More Exciting FizzBuzz
タグ : / 解いたユーザー数 501
作問者 :
Note
This problem was created as the problem for day 9 of Advent Calendar Contest Advent Calendar 2015.Problem Statement
Yumechi is a programming beginner, so he is solving the FizzBuzz problem.
However, the ordinary FizzBuzz problem is too easy, so he wanted to try a slightly more advanced problem.
In ordinary FizzBuzz, "Fizz" is printed for multiples of 3 and "Buzz" for multiples of 5, but Yumechi considers counting the numbers that are multiples of 3 or multiples of 5.
For example, in the range from 1 to 100 inclusive, there are 47 numbers that are multiples of 3 or multiples of 5.
Extending this, Yumechi wants to count, in the range from 1 to N inclusive, the numbers that are multiples of at least one of three integers a, b, c (the numbers that are multiples of a, multiples of b, or multiples of c).
You hate to lose, so when you heard this from Yumechi, you wanted to finish the program before he did, and immediately started coding.
Input
N a b c
The first line contains N, the end of the range, and the second line contains three integers a, b, c.
$ 1 \leq N \leq 10^{9} $
$ 1 \leq a \leq b \leq c \leq 10^{4} $
Output
Print the number of integers in the range from 1 to N inclusive that are multiples of at least one of a, b, c. Print a newline at the end.
Sample
Sample 1
Input
100 2 3 5
Output
74
In the range from 1 to 100 inclusive, there are 74 numbers in total that are multiples of 2, 3, or 5.
Sample 2
Input
100 2 5 6
Output
60
Sample 3
Input
346346 25 575 2525
Output
13853
Sample 4
Input
83359640 3304 9805 9945
Output
42104
(While debugging on my own, I happened to find a pattern that looks painful, so I am adding it here (accident).)
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。