Professional Documents
Culture Documents
Problem W. Can You Eat It: 500 Ms Linux
Problem W. Can You Eat It: 500 Ms Linux
You are a person who is always fond of eating candies. Your friend gave you a candy of length N ,
to eat during the break period of your school.
You start eating this candy from one of the ends. But as it is not your candy, your friend told you
to eat exactly K unit length of candy during each bite. You will stop eating if the candy's length
becomes 0. This means that you have eaten the entire candy.
If at some point of time, the candy's length is positive, but less than K , you cannot take a bite
thereafter.
Can you eat the complete candy? If yes, print the number bites it will take, else print −1.
Input Format
First line will contain T , number of testcases. Then the testcases follow.
Each testcase contains of two spaced integers N , K .
Output Format
For each testcase, print the minimum number of bites you need to eat the complete candy. Print
−1 if it is
not possible to do so.
Constraints
1 ≤ T ≤ 105
0 ≤ N ≤ 106
1 ≤ K ≤ 106
Sample 1
Input Output
3
3
3 1
-1
3 2
0
0 3
Test case 1:
When you eat your first bite of length 1, the length of the candy will become 2. After the second
-
Pratica 01-Instic training Nov 08, 2022
bite, the candy's length will be 1 and finally after the third bite, candy's length will be 0, and
hence you eat the entire candy!
Test case 2:
After the first bite, candy's length will become 1. You cannot go for the second bite as candy's
length is positive and less than 2.
Test case 3:
Candy's length is already 0, hence it can be said that you have eaten the entire candy!