Problem 1 - Multiples of 3 or 5

Author

Vincent Clemson

Published

January 15, 2026

Modified

January 24, 2026

Mirissa, Sri Lanka - April 26th, 2025

If we list all the natural numbers below \(10\) that are multiples of \(3\) or \(5\), we get \(3, 5, 6\) and \(9\). The sum of these multiples is \(23\). Find the sum of all the multiples of \(3\) or \(5\) below \(1000\).

https://projecteuler.net/problem=1

R

Development

We can start with the the first statement, as it eases us into the problem solving.

Finding the sum of all the multiples of \(3\) or \(5\) in the set of natural numbers below \(10\):

Code
threes <- 0
fives <- 0
for (i in 1:10 - 1) {
  if (i %% 5 == 0) fives <- c(fives, i)
  if (i %% 3 == 0) threes <- c(threes, i)
}
sum(unique(c(threes, fives)))
[1] 23

Answer 1

The sum of all the multiples of \(3\) or \(5\) in the set of natural numbers below \(1000\):

Code
threes <- 0
fives <- 0
for (i in 1:1000 - 1) {
  if (i %% 5 == 0) fives <- c(fives, i)
  if (i %% 3 == 0) threes <- c(threes, i)
}
sum(unique(c(threes, fives)))
[1] 233168

Answer 2

Code
x <- seq(1, 999)
sum(x[x %% 5 == 0 | x%%3 == 0])
[1] 233168

Python

Back to top

Reuse

© 2023-2026 Vincent Clemson | This post is licensed under <a href='http://creativecommons.org/licenses/by-nc-sa/4.0/' target='_blank'>CC BY-NC-SA 4.0</a>

Citation

For attribution, please cite this work as:
Clemson, Vincent. 2026. “Problem 1 - Multiples of 3 or 5.” January 15, 2026. https://prncevince.xyz/euler/problem/0001.html.