python code for
Tricks
The Manufacturing hub has a strange way to set things up. It either produces 1 extra item in a day or they
have a power to double the production of items they had on the Prev Day. Initially they had 1 ltem at start
but after some days they had X items.
You need to tell the Minimum NO of days they need to make X items.
Input Format
First Line contains T, the no of test cases.
Next T lines contains a single integer N.
Output Format
For each testcase, Return the Min no of days.
Sample Input
1
8
Sample Output
3
Answers
Program:
sample = int(input("Enter the number of test cases : "))
for i in range(0, sample):
item = int(input("Enter the number of items to be produced : "))
count = 0
while item != 1:
if (item%2 == 0):
item = item / 2
else:
item = item - 1
count = count + 1
print("Minimum number of days : ", count)
Output:
Enter the number of test cases : 1
Enter the number of items to be produced : 8
Minimum number of days : 3
Answer:
C++ code
#include <bits/stdc++.h>
using namespace std;
int main()
{
int t;
cin>>t;
while(t--)
{
int n;
cin>>n;
int cnt=0;
while(n!=1)
{
if(n%2==0)
{
n=n/2;
}
else
{
n=n-1;
}
cnt++;
}
cout<<cnt;
}
return 0;
}
Explanation:
Input:
1
8
Output:3