I propose a mathematical solution.
Number of numbers divided by a is [n/a]
. ([]
is a floor function.)
And about b
, c
, lcm(a, b)
, lcm(a, c)
, lcm(b, c)
, lcm(a, b, c)
so is it. (lcm means least common multiple.)
So the answer should be
([n/a]+[n/b]+[n/c])-([n/lcm(a,b)]+[n/lcm(a,c)]+[n/lcm(b,c)])+[n/lcm(a,b,c)]
7
solved Fastest way to solve the divisibility of numbers [closed]