---
title: "fastPow（ 比pow好用、灵活的）"
author: "DannyYo"
date: "2015-01-05T10:31:23Z"
tags: []
categories: ["编程语言"]
slug: "fastpow-pow"
draft: false
lastmod: "2015-01-05T10:31:23Z"
id: 2172598
url: "https://dannyyo.iteye.com/blog/2172598"
---

#include &lt;iostream&gt;

 

using namespace std;

 

int main()

{

    int a,b;

    cin &gt;&gt; a &gt;&gt; b;

    int res = 1;

    while(b){

            cout &lt;&lt; b;

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

         cout &lt;&lt; "df";

                res\*=a;

        }

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

 

        b=b&gt;&gt;1;

    }

 

    cout &lt;&lt; res;

    return 0;

}