LOCKERS - Daily Coding Problems
1. LOCKERS!
Your college has N lockers. One day you decide to play a game and open only those
lockers that are multiple of M. Initially,
all lockers are closed. Lockers are numbered from 1 to N. Find the number of
lockers that remain closed.
Input Format:
First Line of input contains testcase T.
For each testcase, there will be two lines of input.
·
First line contains the number of lockers N
·
Second line contains M. You will open lockers that are
multiples of M.
Output:
For each testcase print the
number of lockers remain closed.
Sample Input: 2
10
2
12
3
Sample output: 5
8
Explanation: For the test case 1:
N = 10, M = 2
You will open the lockers
which are multiple of 2 that is [2,4,6,8,10]. So the lockers that remain closed
are [1,3,5,7,9] which is equal to 5.
SOLUTION:
We will
loop in a range from 1 to N+1 and check the condition if i is divisible by m
then skip else print the number.
That’s it.
Here goes
the short sweet code:
0 Comments