Given a starting integer K, repeatedly factor it into two factors at least 2, minimizing the maximum number of splits along any root to leaf path.
Medium5GreedyNumber theoryMathRecursionInterviewNo attempts yetTime limit0.5sMemory limit512 MBHi. My name is ntopia.
I used to be an ordinary guy in his twenties living on Earth. One day a stranger stabbed me on the street and I died. When I came to, I had dropped into another world. Here I seem to have become a slime researcher who studies nothing but slimes. I am working on a very important project. If it succeeds, I get to go back to the world I came from. Will you help me with it?
Every slime here holds slime energy, and the amount is a natural number of at least 2. I study how slime energy changes when a slime splits.
A split turns one slime into two. Take a slime with energy K. Split it properly and you get a slime with energy A and a slime with energy B, where A and B are natural numbers of at least 2 and K=A×B always holds. Keep splitting and sooner or later you reach slimes that cannot be split.
The splitting technique is not perfect yet, so every split adds one scratch. Splitting a slime with T scratches produces two slimes with T+1 scratches each.

A slime with energy 24 and 1 scratch being split. It became a slime with energy 4 and 2 scratches and a slime with energy 6 and 2 scratches.
Right now I have a slime with slime energy K and no scratches at all. I have to split it over and over until no slime that can still be split is left. Once everything is split, the slimes at the end carry some number of scratches. (Possibly none.) My goal is to choose the splits so that the largest scratch count among them is as small as possible.
Help me with my research. Please!
The first line contains the energy K (2≤K≤1000000) of the slime you start with.
Print on one line the smallest possible value of the largest scratch count after the slime is split as far as it goes.
Start from a slime with energy 24 and no scratches. Split it into a slime with energy 4 and a slime with energy 6, and both end up with 1 scratch.
The slime with energy 4 and 1 scratch splits into two slimes with energy 2 and 2 scratches.
The slime with energy 6 and 1 scratch splits into a slime with energy 2 and 2 scratches and a slime with energy 3 and 2 scratches.
After that no slime that can be split is left. The largest scratch count here is 2, and no other way of splitting brings it lower.