-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path30.java
38 lines (31 loc) · 790 Bytes
/
30.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
//{ Driver Code Starts
//Initial Template for Java
import java.io.*;
import java.util.*;
class GFG
{
public static void main(String args[])throws IOException
{
BufferedReader read = new BufferedReader(new InputStreamReader(System.in));
int t = Integer.parseInt(read.readLine());
while(t-- > 0)
{
int n = Integer.parseInt(read.readLine());
Solution ob = new Solution();
System.out.println(ob.minStep(n));
}
}
}
// } Driver Code Ends
class Solution{
static int minStep(int n){
int steps = 0;
while(true){
if(n == 1) break;
if(n%3 == 0) n = n/3;
else n = n-1;
steps ++;
}
return steps;
}
}