30:00
You are given positive integers n and m.
n
m
Let num1 be the sum of all integers in [1, n] that are not divisible by m, and num2 the sum of all integers in [1, n] that are divisible by m.
num1
[1, n]
num2
Return num1 - num2.
num1 - num2
1≤n,m≤10001 \leq n, m \leq 10001≤n,m≤1000
Run code to see results.
Lay 1..10 out in rows of m = 3. Every multiple of 3 lands in the last column, so num2 is that column and num1 is everything else.
1..10 in rows of m = 3
not divisible (num1)
divisible (num2)
total = 1 + ... + n
?
k = n // m
num2 = m(1 + ... + k)
num1 = total - num2
Given positive integers n and m, let num1 be the sum of the numbers in [1, n] not divisible by m and num2 the sum of those that are. Return num1 - num2.