{"id":"3e587eac-c8ac-4eda-a9a9-aeebb1f9ea9f","name":"Minimum Number Of Steps To Reduce N","description":"1. You are given a number N.\r\n2. You have to find the minimum number of operations needed to reduce it to 1.\r\n3. operations allowed are - \r\n -> If n is divisible by 2 then you may reduce n to n/2.\r\n -> If n is divisible by 3 then you may reduce n to n/3.\r\n -> Decrement n by 1.","inputFormat":"A number N","outputFormat":"Check the sample output and question video.","constraints":"1 <= arr[i] <= 10^6","sampleCode":{"cpp":{"code":""},"java":{"code":"import java.io.*;\r\nimport java.util.*;\r\n\r\npublic class Main {\r\n\r\n\tpublic static int solution(int n) {\r\n\t\t//write your code here\r\n\r\n\t\treturn 0;\r\n\t}\r\n\t\r\n\tpublic static void main(String[] args) {\r\n\t\tScanner scn = new Scanner(System.in);\r\n\t\tint n = scn.nextInt();\r\n\t\tSystem.out.println(solution(n));\r\n\t}\r\n\r\n}"},"node":{"code":""},"ruby":{"code":""},"python":{"code":""}},"points":10,"difficulty":"easy","sampleInput":"10","sampleOutput":"3\r\n","questionVideo":"","hints":[],"associated":[],"solutionSeen":false,"tags":[],"meta":{"path":[{"id":0,"name":"home"},{"id":"0c54b191-7b99-4f2c-acb3-e7f2ec748b2a","name":"Data Structures and Algorithms","slug":"data-structures-and-algorithms","type":0},{"id":"5539a6e8-c8bf-4f04-805c-e43e9d20e72a","name":"Dynamic Programming For Intermediate","slug":"dynamic-programming-for-intermediate-408","type":0},{"id":"f9db54d1-cfac-4538-8ab8-e94dfe78419b","name":"Minimum Number Of Steps To Reduce N","slug":"minimum-number-of-steps-to-reduce-n","type":1}],"next":{"id":"02f58036-4f64-4bde-81b6-096289a63398","name":"Minimum Number Of Steps To Form N","type":1,"slug":"minimum-number-of-steps-to-form-n"},"prev":{"id":"7204e434-8963-4a03-a8bb-c27698853fd9","name":"Minimum Delta In Partitions","type":1,"slug":"minimum-delta-in-partitions"}}}

Minimum Number Of Steps To Reduce N

1. You are given a number N. 2. You have to find the minimum number of operations needed to reduce it to 1. 3. operations allowed are - -> If n is divisible by 2 then you may reduce n to n/2. -> If n is divisible by 3 then you may reduce n to n/3. -> Decrement n by 1.

{"id":"3e587eac-c8ac-4eda-a9a9-aeebb1f9ea9f","name":"Minimum Number Of Steps To Reduce N","description":"1. You are given a number N.\r\n2. You have to find the minimum number of operations needed to reduce it to 1.\r\n3. operations allowed are - \r\n -> If n is divisible by 2 then you may reduce n to n/2.\r\n -> If n is divisible by 3 then you may reduce n to n/3.\r\n -> Decrement n by 1.","inputFormat":"A number N","outputFormat":"Check the sample output and question video.","constraints":"1 <= arr[i] <= 10^6","sampleCode":{"cpp":{"code":""},"java":{"code":"import java.io.*;\r\nimport java.util.*;\r\n\r\npublic class Main {\r\n\r\n\tpublic static int solution(int n) {\r\n\t\t//write your code here\r\n\r\n\t\treturn 0;\r\n\t}\r\n\t\r\n\tpublic static void main(String[] args) {\r\n\t\tScanner scn = new Scanner(System.in);\r\n\t\tint n = scn.nextInt();\r\n\t\tSystem.out.println(solution(n));\r\n\t}\r\n\r\n}"},"node":{"code":""},"ruby":{"code":""},"python":{"code":""}},"points":10,"difficulty":"easy","sampleInput":"10","sampleOutput":"3\r\n","questionVideo":"","hints":[],"associated":[],"solutionSeen":false,"tags":[],"meta":{"path":[{"id":0,"name":"home"},{"id":"0c54b191-7b99-4f2c-acb3-e7f2ec748b2a","name":"Data Structures and Algorithms","slug":"data-structures-and-algorithms","type":0},{"id":"5539a6e8-c8bf-4f04-805c-e43e9d20e72a","name":"Dynamic Programming For Intermediate","slug":"dynamic-programming-for-intermediate-408","type":0},{"id":"f9db54d1-cfac-4538-8ab8-e94dfe78419b","name":"Minimum Number Of Steps To Reduce N","slug":"minimum-number-of-steps-to-reduce-n","type":1}],"next":{"id":"02f58036-4f64-4bde-81b6-096289a63398","name":"Minimum Number Of Steps To Form N","type":1,"slug":"minimum-number-of-steps-to-form-n"},"prev":{"id":"7204e434-8963-4a03-a8bb-c27698853fd9","name":"Minimum Delta In Partitions","type":1,"slug":"minimum-delta-in-partitions"}}}
plane

Editor


Loading...

Minimum Number Of Steps To Reduce N

easy

1. You are given a number N. 2. You have to find the minimum number of operations needed to reduce it to 1. 3. operations allowed are - -> If n is divisible by 2 then you may reduce n to n/2. -> If n is divisible by 3 then you may reduce n to n/3. -> Decrement n by 1.

Constraints

1 <= arr[i] <= 10^6

Format

Input

A number N

Output

Check the sample output and question video.

Example

Sample Input

10

Sample Output

3

Discussions

Show Discussion

Related Resources

related resources

Turning Off Zen Mode