luogu#P10494. [USACO02FEB] Power Hungry Cows

    ID: 672 远端评测题 1000ms 512MiB 尝试: 0 已通过: 0 难度: (无) 上传者: 标签>2002USACOO2优化启发式迭代加深搜索,IDA*

[USACO02FEB] Power Hungry Cows

题目描述

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:

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.

输入格式

A single line with one integer: P.

输出格式

A single line with a single integer that is the minimum number of operations it requires to compute the pow

题目大意

【题目描述】

FJ 的奶牛们希望能够快速计算整数幂 PP1P200001 \leq P \leq 20000),但她们需要你的帮助。因为她们将要计算非常大的数的幂,所以她们只能保留两个工作变量来存储中间结果。

这两个工作变量中的第一个被初始化为正在计算幂的数字(表示为 xx);另一个被初始化为 11。奶牛们可以对任意一对工作变量进行乘法和除法运算,并将结果存储在任意一个工作变量中,但所有结果都存储为整数。

例如,如果她们想要计算 x31x^{31},一种进行计算的方法是:

因此,x31x^{31} 可以在六次操作中计算出来。给定要计算的幂和工作变量的数量,找出计算该幂所需的最少操作数。

【输入格式】

一行,一个整数:PP

【输出格式】

一行,一个整数,表示计算幂所需的最小操作数。

翻译来自于:ChatGPT

31
6