← All problemsSign in

Achieving One

You are given a number X and an array A of N numbers. You have to reduce the number X to 1 using a minimum number of steps. Here a step is defined as dividing the number X by a number present in that array, say Y and replace X by X/Y, also this can be done only if X is divisible by Y. You can divide by the same number multiple times. If it is not possible print -1 else print the number of steps.

HINT LADDERno hints yet
L1 Observation
L2 Technique
L3 Approach
L4 Pseudo-code
🔒
L5 Full solution
L5 unlocks only if you insist twice
solution.cppC++17

CodeSearch Tutor

Hints, not spoilers — it won’t hand over the full solution unless you insist.

voice by Sarvam AI

Sign in to chat with the tutor and save your progress.

Sign in to start