快速幂 随笔 第1张

快速幂 随笔 第2张

杭电oj ----1061

#include <cstdio>
#include <cstring>
using namespace std;
int ksm(int n,int m){
    int res=1;
    while(m!=0)
    {
        if(m&1)
            res=res*n%10;
        n=n*n%10;
        m>>=1;
    }
    res=n*res%10;
    return res;
}
int main()
{
    int t,n;
    scanf("%d",&t);
    while(t--)
    {
        scanf("%d",&n);
        printf("%d\n",ksm(n%10,n));
    }
    return 0;
}

SRE实战 互联网时代守护先锋,助力企业售后服务体系运筹帷幄!一键直达领取阿里云限量特价优惠。
扫码关注我们
微信号:SRE实战
拒绝背锅 运筹帷幄