All problems
0904EasyMath

Marks Struck Off by Three, Five or Seven

Tracked in this browser only
Write code

Trains the technique from

LeetCode 2652Sum Multiples

This is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.

Same function shape, different story and different numbers.

A tally sheet is marked 1 through n.

A mark is struck off when it divides evenly by 3, by 5 or by 7. Return the total of the marks struck off.

Examples

Example 1

Input
n = 143
Output
5523

Every multiple of 3, 5 or 7 up to 143 is struck off, and their total comes to this once the overlaps have been settled.

Example 2

Input
n = 15
Output
81

The marks struck off are 3, 5, 6, 7, 9, 10, 12, 14 and 15, which total 81. The mark 15 divides by both 3 and 5 yet is counted once.

Example 3

Input
n = 2
Output
0

Neither mark divides by 3, 5 or 7.

Constraints

  • 1 <= n <= 10^3

The signature

The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.

Python
def sum_of_multiples(n: int) -> int:
Java
public int sumOfMultiples(int n)
September 7
Apply