In this HackerEarth Count Divisors problem solution, you have been given 3 integers - l, r, and k. Find how many numbers between l and r (both inclusive) are divisible by k. You do not need to print these numbers, you just have to find their count.


hackerEarth Count Divisors problem solution


HackerEarth Count Divisors problem solution.

import java.io.*;
import java.util.*;
class example_2
{
    static Scanner sc=new Scanner(System.in);

    public static void main(String args[]) throws Exception
    {
        int l=sc.nextInt(),r=sc.nextInt(),k=sc.nextInt();
        System.out.println((r/k)-((l-1)/k));
    }
}