Count Divisors - Hackerearth Problem Solution - CODELABS3277

So with the hope that you have tried to solve
this problem, if not then please give it a try before seeing the solutions.

If already tried then here we will be exploring numerous ways to solve this problem. Though it is a very basic problem from Basic Programming Section!


Given: 3 integers - l, r, and k.
Find how many numbers between l and r (both inclusive) are divisible by k.
We need to print the count of such numbers.
Constraints
1lr1000

Solution 1:

So we will run a loop from i=l to i=r and check whether i%k==0 or not and if divisible then increment the value of variable counter else not and at the end, we will print it.

By - PraveenKumarRana

If you find any error in explanation or in code, do write in the comment section.  These are the codes which I have written and submitted in Hackerearth.

Thank You
Happy Coding
Enjoy!

Comments