Count Divisors

problem:-

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.
Input Format
The first and only line of input contains 3 space separated integers lr and k.
Output Format
Print the required answer on a single line.
Constraints

1lr1000


1k1000

SAMPLE INPUT
1 10 1
SAMPLE OUTPUT
10
Time Limit:1.0 sec(s) for each input file.
Memory Limit:256 MB
Source Limit:1024 KB

Solution:-

#include<stdio.h>
void main()
{
int i,r,k,n,s=0;
scanf(“%d%d%d”,&i,&r,&k);
for(n=i;n<=r;n++)
{
if(n%k==0)
s++;
}
printf(“%d”,s);
}

Leave a Reply

Your email address will not be published.