51nod 1004 n^n的末位数字

求n的n次方的末尾数字

大概都知道暴力 模拟一下  但是 N 是10^9级别的 会T

所以用   快速幂  要是求n的阶乘就不行了呢

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod = 10;
int  _pow(ll x,ll n)
{
    int res = 1;
    while (n > 0)
    {
        if(n & 1) res = res * x %mod;
        x = x * x %mod;
        n >>=1;
    }
    return res;
}


int main ()
{
    int n;
    scanf("%d",&n);
    printf("%d
",_pow(n,n));
}
原文地址:https://www.cnblogs.com/Draymonder/p/7367883.html