最少乘法次数
最少乘法次數
時間限制:1000?ms ?|? 內存限制:65535?KB 難度:3 描述給你一個非零整數,讓你求這個數的n次方,每次相乘的結果可以在后面使用,求至少需要多少次乘。如24:2*2=22(第一次乘),22*22=24(第二次乘),所以最少共2次;
???????????????
每一組測試數據有一整數n(0<n<=10000);
#include <iostream>
using namespace std;
int main(int argc, char* argv[])
{
int t;
cin>>t;
while(t--)
{
int n,count;
cin>>n;
count=0;
while(n!=1)
{
count++;
if(n%2==1) count++;
n=n/2;
}
cout<<count<<endl;
}
return 0;
}
轉載于:https://www.cnblogs.com/52Cyan/p/3681753.html
與50位技術專家面對面20年技術見證,附贈技術全景圖總結
- 上一篇: 自动编译和提交脚本(结合svn和visu
- 下一篇: IIS系列问题