Computer Science, asked by rsmanasa98, 8 months ago

Java code for TricksThe Manufacturing hub has a strange way to set things up. It either produces 1 extra item in a day or theyhave a power to double the production of items they had on the Prev Day. Initially they had 1 ltem at startbut after some days they had X items.You need to tell the Minimum NO of days they need to make X items.Input FormatFirst Line contains T, the no of test cases.Next T lines contains a single integer N.Output FormatFor each testcase, Return the Min no of days.Sample Input18Sample Output3​

Answers

Answered by sainitinreddy99
20

Answer:

import java.util.Scanner;

public class Exam2 {

public static void main(String[] args) {

// TODO Auto-generated method stub

Scanner sc=new Scanner(System.in);

int n;

n=sc.nextInt();

int j=0,c=1;

if(c<n) {

j=fun(n,c,j);

}

System.out.println(j);

}

private static int fun(int n, int c,int j) {

// TODO Auto-generated method stub

int m1,m2;

if(c>n) {

return Integer.MAX_VALUE;

}else if(c==n) {

return j;

}else {

m1=fun(n,c+1,j+1);

m2=fun(n,c*2,j+1);

if(m1<m2) {

return m1;

}else {

return m2;

}

}

}

}

Explanation:

for input 6:

days will be 3 because

initially there will be 1 product , then

1 -> 2 -> 3 -> 6

total of 3 days

Similar questions