A vineyard's watchtower keeper rings a warning bell at dawn on any day of the growing season whose day number is evenly divisible by 3 (check for frost), by 5 (check for pests), or by 7 (check for drought stress). A day that satisfies more than one of these conditions still only rings the bell once, but the keeper wants to know the total of all the day numbers on which the bell rang, in order to plan supply runs for the season.
Given the number of days in the growing season, compute the sum of every day number from 1 up to that count (inclusive) that is a multiple of 3, 5, or 7.
A single line containing one integer n, the number of days in the growing season.
Print a single integer: the sum of all day numbers in [1, n] that are divisible by 3, 5, or 7 (each qualifying day counted once).
Example 1
Input
7
Expected
21
Explanation
Within days 1 through 7, the multiples of 3 are 3 and 6, the multiple of 5 is 5, and the multiple of 7 is 7. The distinct qualifying days are 3, 5, 6, 7, which sum to 21.
Example 2
Input
10
Expected
40
Explanation
Within days 1 through 10, the multiples of 3 are 3, 6, 9, the multiples of 5 are 5, 10, and the multiple of 7 is 7. The distinct qualifying days are 3, 5, 6, 7, 9, 10, which sum to 40.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →