[USACO02FEB] Power Hungry Cows

Luogu
IDLGP10494
Time1000ms
Memory512MB
DifficultyP5
2002USACOO2优化广度优先搜索 BFS剪枝迭代加深搜索启发式迭代加深搜索 IDA*
FJ's cows would like to be able to compute integer powers P (1 <= P <= 20,000) of numbers very quickly, but need your help. Because they're going to be computing powers of very large numbers, they can only keep around two work variables for intermediate results. The first of those work variables is initialized to the number (denoted x) for which they are calculating the power; the other is initialized to 1. The cows can both multiply and divide any pair of the work variables and store the result in any work variable, but all results are stored as integers. For example, if they want to compute x^31, one way to perform the calculation is: ![](https://cdn.luogu.com.cn/upload/image_hosting/bfbznh12.png) Thus, x^31 can computed in six operations. Given the power to be computed and the the number of work variables, find the minimum number of operations to calculate the power. ## Input A single line with one integer: P. ## Output A single line with a single integer that is the minimum number of operations it requires to compute the pow [samples]
Samples
Input #1
31
Output #1
6
API Response (JSON)
{
  "problem": {
    "name": "[USACO02FEB] Power Hungry Cows",
    "description": {
      "content": "FJ's cows would like to be able to compute integer powers P (1 <= P <= 20,000) of numbers very quickly, but need your help. Because they're going to be computing powers of very large numbers, they can",
      "description_type": "Markdown"
    },
    "platform": "Luogu",
    "limit": {
      "time_limit": 1000,
      "memory_limit": 524288
    },
    "difficulty": {
      "LuoguStyle": "P5"
    },
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "LGP10494"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "FJ's cows would like to be able to compute integer powers P (1 <= P <= 20,000) of numbers very quickly, but need your help. Because they're going to be computing powers of very large numbers, they can...",
      "is_translate": false,
      "language": "English"
    }
  ]
}
Full JSON Raw Segments