Editorial for Mock CCC '19 Contest 1 J2 - Froggo's Numbers


Remember to use this editorial only when stuck, and not to copy-paste code from it. Please be respectful to the problem author and editorialist.

Submitting an official solution before solving the problem yourself is a bannable offence.

Authors: jsumabat

If we want to determine the how many integers are divisible by x in the range of l to r, then lets represent this as a function, such that f(n) is equal to the number of integers that are divisible by x greater than or equal to 0, and less than or equal to n.

If we represent f(n) using the above definition, then realistically, f(r) - f(l-1) (like a prefix sum array, or inclusion-exclusion principle) is the solution. However, if l = 0, then we end up having f(-1), which is invalid.

We can rewrite f(n) like so, where in division, decimals are truncated:

\displaystyle  f(n) = \begin{cases}n/x+1 & (n \ge 0)\\0 & (n = -1)\end{cases}


Comments


  • 0
    Jonathan_Hong  commented on Dec. 12, 2019, 1:25 p.m.

    I can't read I need help : ^)