2541 幂运算
Posted 神犇(shenben)
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了2541 幂运算相关的知识,希望对你有一定的参考价值。
题目描述 Description
从m开始,我们只需要6次运算就可以计算出m31:
m2=m×m,m4=m2×m2,m8=m4×m4,m16=m8×m8,m32=m16×m16,m31=m32÷m。
请你找出从m开始,计算mn的最少运算次数。在运算的每一步,都应该是m的正整数次方,换句话说,类似m-3是不允许出现的。
输入描述 Input Description
输入为一个正整数n
输出描述 Output Description
输出为一个整数,为从m开始,计算mn的最少运算次数。
样例输入 Sample Input
样例1
1
样例2
31
样例3
70
样例输出 Sample Output
样例1
0
样例2
6
样例3
8
数据范围及提示 Data Size & Hint
n(1<=n<=1000)
数据没有问题,已经出现过的n次方可以直接调用
史上最有潜力的打表,快来围观!
#include<iostream> using namespace std; int a[1001]={0,0,1,2,2,3,3,4,3,4,4,5,4,5,5,5,4,5,5,6,5, 6,6,6,5,6,6,6,6,7,6,6,5,6,6,7,6,7,7,7,6, 7,7,7,7,7,7,7,6,7,7,7,7,8,7,8,7,8,8,8,7, 8,7,7,6,7,7,8,7,8,8,8,7,8,8,8,8,8,8,8,7, 8,8,8,8,8,8,9,8,9,8,9,8,8,8,8,7,8,8,8,8, 9,8,9,8,9,9,9,8,9,9,9,8,9,9,9,9,9,9,9,8, 9,9,9,8,9,8,8,7,8,8,9,8,9,9,9,8,9,9,9,9, 9,9,9,8,9,9,9,9,9,9,10,9,9,9,9,9,9,9,9,8, 9,9,9,9,9,9,10,9,10,9,10,9,10,10,10,9,10,10,10,9, 10,10,10,9,10,9,10,9,9,9,9,8,9,9,9,9,10,9,10,9, 10,10,10,9,10,10,10,9,10,10,10,10,10,10,10,9,10,10,10,10, 10,10,10,9,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,9, 10,10,10,10,10,10,10,9,10,10,10,9,10,9,9,8,9,9,10,9, 10,10,10,9,10,10,11,10,11,10,10,9,10,10,11,10,11,10,10,10, 10,10,10,10,10,10,10,9,10,10,10,10,10,10,11,10,10,10,11,10, 11,11,11,10,11,10,11,10,11,10,11,10,11,10,10,10,10,10,10,9, 10,10,10,10,10,10,11,10,11,10,11,10,11,11,11,10,11,11,11,10, 11,11,11,10,11,11,11,11,11,11,11,10,11,11,11,11,11,11,11,10, 11,11,11,11,11,11,11,10,11,11,11,10,11,11,11,10,11,10,11,10, 10,10,10,9,10,10,10,10,11,10,11,10,11,11,11,10,11,11,11,10, 11,11,11,11,11,11,11,10,11,11,11,11,11,11,11,10,11,11,11,11, 11,11,11,11,11,11,11,11,11,11,11,10,11,11,11,11,11,11,11,11, 11,11,11,11,11,11,11,10,11,11,11,11,11,11,11,11,11,11,11,11, 12,11,12,11,11,11,12,11,12,11,11,11,11,11,11,11,11,11,11,10, 11,11,11,11,11,11,11,11,11,11,12,11,12,11,11,10,11,11,12,11, 12,11,11,10,11,11,11,10,11,10,10,9,10,10,11,10,11,11,11,10, 11,11,12,11,12,11,11,10,11,11,12,11,12,12,11,11,12,12,12,11, 12,11,11,10,11,11,12,11,12,12,12,11,11,12,12,11,12,11,12,11, 11,11,12,11,12,11,11,11,12,11,11,11,11,11,11,10,11,11,11,11, 11,11,12,11,11,11,12,11,12,12,12,11,12,11,12,11,12,12,12,11, 12,12,12,12,12,12,12,11,12,12,12,11,12,12,12,11,12,12,12,11, 12,12,12,11,12,12,12,11,12,11,12,11,12,11,11,11,11,11,11,10, 11,11,11,11,11,11,12,11,12,11,12,11,12,12,12,11,12,12,12,11, 12,12,12,11,12,12,12,12,12,12,12,11,12,12,12,12,12,12,12,11, 12,12,12,12,12,12,12,11,12,12,12,12,12,12,12,12,12,12,12,12, 12,12,12,11,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,11, 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,11,12,12,12,12, 12,12,12,11,12,12,12,12,12,12,12,11,12,12,12,11,12,12,12,11, 12,11,12,11,11,11,11,10,11,11,11,11,12,11,12,11,12,12,12,11, 12,12,12,11,12,12,12,12,12,12,12,11,12,12,12,12,12,12,12,11, 12,12,12,12,12,12,12,12,12,12,13,12,12,12,12,11,12,12,12,12, 13,12,12,12,12,12,12,12,12,12,12,11,12,12,12,12,12,12,12,12, 12,12,12,12,12,12,13,12,12,12,13,12,13,12,12,12,13,12,12,12, 12,12,12,11,12,12,12,12,12,12,13,12,12,12,13,12,13,12,12,12, 13,12,13,12,13,12,12,12,12,12,12,12,12,12,12,11,12,12,12,12, 12,12,12,12,12,12,13,12,13,12,13,12,13,12,13,12,13,12,13,12, 13,13,13,12,13,13,13,12,13,12,13,12,13,13,13,12,13,13,13,12, 13,12,13,12,12,12,13,12,13,12,12,12,12,12,12,12,12,12,12,11, 12,12,12,12,12,12,12,12,12,12,13,12,13,12,12,12,12,12,13,12, 13,13,13,12,13,13,13,12,13,12,12,11,12,12,13,12,13,13,13,12 }; int main(){ int n; cin>>n; cout<<a[n]<<endl; return 0; }
以上是关于2541 幂运算的主要内容,如果未能解决你的问题,请参考以下文章