The Problem

Find the sum of all multiples of 3 or 5 below 1000. For the worked example, the multiples below 10 are 3, 5, 6 and 9, which sum to 23. Generalise to an arbitrary bound and return the total.

The Algorithm

The naïve method walks every integer below and tests divisibility — correct, but . The insight is that the multiples of a divisor form an arithmetic series, so their sum has a closed form. Add the series for 3 and for 5, then subtract the series for 15, whose multiples were counted twice (inclusion–exclusion).

With the triangular number, the whole answer is a handful of multiplications:

No loop, no growth with — the work is constant, , and stays exact for bounds far beyond 1000.

The Prompt

Prompt · sent identically to all three

Solve Project Euler Problem 1 in Python. Find the sum of all multiples of 3 or 5 below a given bound n. Use the closed-form approach: sum each arithmetic series and apply inclusion-exclusion for the multiples of 15 - do not brute-force a loop. Signature: solve(n: int) -> int, returning the sum. Print solve(1000).

Sent to
Claude
GPT
Gemini

The Solutions

×
−
⤢
1def sum_multiples(limit: int) -> int:
2 """Sum of every multiple of 3 or 5 below `limit`."""
3 def series(step: int) -> int:
4 n = (limit - 1) // step
5 return step * n * (n + 1) // 2
6 
7 # inclusion-exclusion: 3s + 5s - 15s (double counted)
8 return series(3) + series(5) - series(15)
9 
10 
11print(sum_multiples(1000)) # 233168

Results

ANSWER
233168
✓ all correct · 233168
WINNER
Claude15/15 · closed-form, cleanest

All three returned 233168. Claude and GPT both recognised the closed form — sum the arithmetic series for each divisor and subtract the multiples of 15 counted twice — collapsing the whole thing to constant-time arithmetic. Gemini was correct too, but reached for the obvious loop over every integer below the bound.

Claude edged it: a typed helper, a one-line docstring, and the inclusion–exclusion spelled out in a comment, with nothing extra. GPT's math was identical but a touch barer. Gemini's loop is perfectly readable — it just ignores the very insight the prompt handed it, which is what costs it on verbosity and speed.

THE BREAKDOWN
METRICCLAUDEGPTGEMINI
Instruction following
Verbosity
Truthfulness
Speed0.4 µs0.5 µs84 µs
Peak RAM9.1 MB9.2 MB9.4 MB
Cost$0.0142$0.0068$0.0031
JUDGED TOTAL15/1514/1512/15