Published
Edited
Jan 28, 2021
Insert cell
md`# Untitled`
Insert cell
sumOfMultiples = (n, x) => {
const NX = Math.floor((n - 1) / x);
return (NX * (NX + 1) * x) / 2;
}
Insert cell
sumOfMultiples(N, X)
Insert cell
Insert cell
Insert cell
Insert cell
f = (n, x, y) => sumOfMultiples(n, x) + sumOfMultiples(n, y) - sumOfMultiples(n, x * y)
Insert cell
f2 = (n, x, y) => {
let sum = 0;
for (let i = 0; i < n; i++) {
if (i % x === 0 || i % y === 0) {
sum += i;
}
}
return sum;
}
Insert cell
f(N, X, Y)
Insert cell
f2(N, X, Y)
Insert cell
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more