Minimum decrements or division by a proper divisor required to reduce N to 1 | Function to find the minimum number of steps required to reduce N to 1 ; Stores the number of steps required ; If the value of N is equal to 2 or N is odd ; Decrement N by 1 ; Increment cnt by 1 ; If N is even ; Update N ; Increment cnt by 1 ; Return the number of steps obtained ; Driver Code
function reduceToOne ( N ) { let cnt = 0 ; while ( N != 1 ) { if ( N == 2 || ( N % 2 == 1 ) ) { N = N - 1 ; cnt ++ ; } else if ( N % 2 == 0 ) { N = Math . floor ( N / Math . floor ( N / 2 ) ) ; cnt ++ ; } } return cnt ; } let N = 35 ; document . write ( reduceToOne ( N ) ) ;