Problem Statement
There are three types of operations you can perform on an integer:
- 1. If it's divisible by 3, divide it by 3.
- 2. If it's divisible by 2, divide it by 2.
- 3. Subtract 1.
Definition
- Class:
- DecreasingNumber
- Method:
- numberOfOperations
- Parameters:
- int
- Returns:
- int
- Method signature:
- int numberOfOperations(int n)
- (be sure your method is public)
Constraints
- n will be between 1 and 106, inclusive.
Examples
1
Returns: 0
We are already at number 1.2
Returns: 1
Only divide it by 2.5
Returns: 3
First, substract 1. Then, divide by 2 twice. (Or substract 1 twice, and then divide by 3).10
Returns: 3
First, substract 1. Then, divide by 3 twice.962340
Returns: 17