ITeye博客

fastPow( 比pow好用、灵活的)

DannyYo · 2015-01-05 10:31 · 算法 · c++ · 编程语言 · Markdown

#include <iostream>

 

using namespace std;

 

int main()

{

    int a,b;

    cin >> a >> b;

    int res = 1;

    while(b){

            cout << b;

        if(b&1) { //位运算 与 末尾为1

         cout << "df";

                res*=a;

        }

        a*=a; //a的2、4、8、16次方 所以比pow 的快

 

        b=b>>1;

    }

 

    cout << res;

    return 0;

}

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。