#P2064. 奇妙的汽车

奇妙的汽车

Description

You have a wonderful car with an auto-acceleration feature. For example, on day 11 you can drive a distance of aa. Then on day 22, you can increase the distance to one of 22 to 99 times that of day 11 (it must be one of these integers), that is, from 2a2a to 9a9a. On day 33, the distance will be 22 to 99 times that of day 22, and so on. In other words, on day ii, the distance must be 22 to 99 times that of day i1i-1, and it must be an integer multiple of it.

You are eager to drive this car from city AA to city BB for a trip and show off this extraordinary car along the way. You already know the total mileage SS you need to travel. Please determine the day 11 distance and the multiplier used each subsequent day so that the total distance is exactly SS and the number of days is minimized.

However, because you want to show off your car properly and for safety reasons, you are required to spend at least 22 days. If no such plan exists, output -1.

Input Format

A positive integer SS, representing the distance from city AA to city BB.

Output Format

A single integer representing the minimum number of days required; if there is no solution, output -1.

15121
-1
571
5

Hint

Constraints

  • For 30%30\% of the testdata, S100S \leq 100.
  • For 70%70\% of the testdata, S107S \leq 10^7.
  • For 100%100\% of the testdata, 9<S1089 < S \leq 10^8.

Translated by ChatGPT 5