Skip to the content.

Asked by PagerDuty

Question

Given a positive integer N, find the smallest number of steps it will take to reach 1.

There are two kinds of permitted steps:

1. You may decrement N to N - 1.

2. If a * b = N, you may decrement N to the larger of a and b.

For example, given 100, you can reach 1 in five steps with the following route: 100 -> 10 -> 9 -> 3 -> 2 -> 1