快速幂模版

#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
int f(int x,int n)
{
    int now=1;
    while(n)
    {
        if(n&1)
        {
            now=now*x;
        }
        x=x*x;
        n>>=1;
    }
    return now;
}
int main()
{
    int x,n;
    cin>>x>>n;
    cout<<f(x,n);
    return 0;
}
原文地址:https://www.cnblogs.com/sssy/p/6680069.html