Following the solution.
public int algo(int Y, int Z, int N) { if ( Z==0 ) { return 1; } if (Z != 0) { return Z/N - ((Y-1)/N); } else { return Z/N +1; } }
Following the math explanation.
The quantity of integers divisible by N in the range [1 .. Z] is Z/N. Then in the range [Z .. Y], the result is =Y/N – ((Z – 1)/N). Also, zero is divisible by any number which answer is 0.