Reactor Compression Steps
Preview mode. Log in to edit, run, submit, and save progress.
Reactor Compression Steps
A reactor value can be changed with two operations: divide it by 6 if it is currently divisible by 6, or multiply it by 2. For each starting value n, find the minimum number of operations needed to make the value exactly 1. If no sequence of allowed operations can reach 1, print -1. Input Format: The first line contains t, the number of test cases. Each test case contains n. Output Format: For each test case, print the minimum operation count, or -1 if the target cannot be reached.
Examples
1 12
-1
Explanation: Dividing 12 by 6 gives 2, and from 2 the allowed operations cannot reach 1. Other allowed sequences also fail to reach exactly 1.
Approach hint
Start with a simple approach, explain the trade-off, then move toward a cleaner or more scalable solution.
Common mistake
Skipping assumptions, edge cases, or trade-offs can make an otherwise good answer feel incomplete.
1
12-1