Maybe you can try the code below
sum_mult <- function(n, v) sum(seq(n)[rowSums(sapply(v, function(x) seq(n) %% x) == 0) > 0])
such that
> sum_mult(5, c(2, 3))
[1] 9
> sum_mult(10, c(3, 5))
[1] 33
> sum_mult(100, c(3, 4, 5))
[1] 3046
Update
if you want to count common multiples once or multiple times
sum_mult <- function(n, v) sum(sapply(v, function(x) sum(seq(n)[seq(n) %% x==0])))
Such that
> sum_mult(5, c(2, 3))
[1] 9
> sum_mult(10, c(3, 5))
[1] 33
> sum_mult(100, c(3, 4, 5))
[1] 4033
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…