码迷,mamicode.com
首页 > 其他好文 > 详细

2541 幂运算

时间:2016-06-10 16:28:22      阅读:207      评论:0      收藏:0      [点我收藏+]

标签:

2541 幂运算

 

 时间限制: 1 s
 空间限制: 128000 KB
 题目等级 : 钻石 Diamond
 
 
题目描述 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次方可以直接调用

分类标签 Tags 点此展开 

 
史上最有潜力的打表,快来围观!
#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 幂运算

标签:

原文地址:http://www.cnblogs.com/shenben/p/5573678.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!