Hi everyone,
Today's codeforces round involved finding the number of occurrences of a certain AP in a range, for example 1,3,5,7... in a range of 0 to 99.
A lot of users have solved the problem with:
if((n-1)<c) return 0; return (n-1-c)/b + 1;
Although such one liners seem simple, basic maths, they are tricky and error prone to come up with during contests, with even some higher rated coders making mistakes in the same. How can I improve this aspect of my maths?
Thanks for your time.
PS: I still don't know why this formula works. Any further problems requiring similar ideas would be appreciated.









It is not as hard as you think.
-The array is constructed using this formula b * i + c.
-An element of the array will be kept in the permutation if is in the range [0, n-1]
so for an element to be valid it should meet this condition :
b * i + c <= n-1.
so 0 <= i <= (n-1-c)/b, so valid numbers = (n-1-c)/b — 0 + 1.
-the remaining we need to add to permuatation will be n — valid ones, which is the answer to the problem