51Nod1004

思路

快速幂模板题

AC代码

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define inf 0x3f3f3f3f

const int mod=10;

void ksm(ll x,ll n)
{
    ll res=1;
    while(n)
    {
        if(n&1)
            res=res*x%mod;
        x=x*x%mod;
        n>>=1;
    }
    cout<<res<<endl;
}

int main()
{
    ll n;
    cin>>n;
    ksm(n,n);
    return 0;
}
原文地址:https://www.cnblogs.com/OFSHK/p/14658782.html