Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.

book
Reduce a Number to One

You are given an integer n. In one move, you can either: Multiply n by 2, or Divide n by 6 (only if it is divisible by 6 without a remainder). Return the minimum number of moves needed to obtain 1 from n, or return -1 if it's impossible to do so.

Example 1

Input:

1

Output:

0

Example 2

Input:

2

Output:

-1
main.cpp

main.cpp

C++

Spørg AI

expand

Spørg AI

ChatGPT

Spørg om hvad som helst eller prøv et af de foreslåede spørgsmål for at starte vores chat

some-alt