For this Question: You are given the number N. You need to convert it to 1 in the minimum number of operations.
The operations allowed are as follows:
1. If N is even then divide the number by 2.
2. If N is odd then you can either add 1 to it or subtract 1 from it.
Using the above operations, find the minimum number of operations required to convert N to 1.The first line of input contains an integer T denoting the number of test cases. T test cases follow.  Each test case contains 1 line of input containing integer N.

<b>Constraints:</b>
1 &le; T &le; 100
1 &le; N &le; 10<sup>7</sup>
For each testcase, in a new line, print the minimum number of steps required.Sample Input:
4
1
2
3
4

Sample Output:
0
1
2
2

<b>Explanation:</b>
1 can be converted into 1 in 0 steps.
2 can be converted into 1 in 1 step: 2/2=1
3 can be converted into 1 in 3 steps: 3-1= 2 then 2/2=1
4 can be converted into 1 in 2 steps:  4/2=2 then 2/2=1, I have written this Solution Code: import java.lang.*;
import java.io.*;
import java.util.*;

class Main {
	public static void main (String[] args) {
	    
		Scanner sc=new Scanner(System.in);
		int testcases=sc.nextInt();
		
		while(testcases-->0)
		{
		    long n=sc.nextLong();
		    System.out.println(NS.minOperations(n));
		   
		}
	}
}

class NS
{
    public static long minOperations(long n)
    {
        if(n==1) 
        return 0; //since 1 is already 1
        if(n==2)
        return 1; //convert 2 to 1. 1 step
        if(n==3)
        return 2; //convert 3 to 2. Then 2 to 1. 2 steps
        long total=0; //save total steps
        if(n%2!=0) //if odd
        {
              total=1+Math.min(minOperations(n-1),minOperations(n+1)); 
              //convert n to n-1 or n+1 then minimum of those conversions
        }
        else
        total=1+minOperations(n/2); //convert n to n/2 then count operations required for n/2 to 1
        
        return total; //returning total at the end
    }
}, In this Programming Language: Java, Now tell me if this Code is compilable or not?