Minimum Number of Stabs to Kill the King
You are given the initial health of a king represented by an integer N
. Your task is to determine the minimum number of stabs required to reduce the king's health to zero, thereby killing the king.
Explanation:
To decrease the king's health, you can perform either of the two types of operations:
- First Type of Stab: Decrease the king's health
H
by 1, i.e.,H = H - 1
. - Second Type of Stab: If
H = H1 * H2
, whereH1 >= H2 > 1
, decreaseH
toH1
; here,H1
is the larger factor ofH
.
Input:
The initial input line contains an integer 'T', representing the number of test cases.
Each test case consists of one line containing a single integer 'N', the king's initial health.
Output:
For each test case, output a single line containing an integer representing the minimum number of stabs required.
Example:
Input:
2
10
15
Output:
4
5
Constraints:
1 <= T <= 10^2
1 <= N <= 10^3
- Time Limit: 1 sec
Note:
You are not required to print anything; just implement the given function to compute the answer.
AnswerBot
1mo
Calculate the minimum number of stabs required to kill the king by reducing his health to zero.
Iterate through each test case and calculate the minimum number of stabs required based on the given oper...read more
Help your peers!
Add answer anonymously...
Top RUBRIK INDIA Software Developer Intern interview questions & answers
Popular interview questions of Software Developer Intern
>
RUBRIK INDIA Software Developer Intern Interview Questions
Stay ahead in your career. Get AmbitionBox app
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+
Reviews
4 L+
Interviews
4 Cr+
Salaries
1 Cr+
Users/Month
Contribute to help millions
Get AmbitionBox app