【模板】快速幂

来源:互联网 发布:电脑降温软件排名 编辑:程序博客网 时间:2024/05/29 03:27
#include<iostream>#include<cstdio>using namespace std;int a,b;int ksm(int a,int b){    if(b==0) return 1;    int ans=1;    while(b)    {        if(b&1) ans*=a;        a*=a;        b>>=1;     }    return ans;}int main(){    scanf("%d%d",&a,&b);    printf("%d",ksm(a,b));    return 0;}