Java Count Div
public class Solution {
public static int countDiv(int a, int b, int k) {
int firstDiv = a % k == 0 ? a : a + (k - a % k);
int lastDiv = b - b % k;
return (lastDiv - firstDiv) / k + 1;
}
}
This counts how many numbers in a range are divisible by K without looping through every value.