首页 > 其他 > 详细

51nod 1004 n^n的末位数字

时间:2017-08-15 21:41:18      阅读:254      评论:0      收藏:0      [点我收藏+]

求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\n",_pow(n,n));
}

 

51nod 1004 n^n的末位数字

原文:http://www.cnblogs.com/Draymonder/p/7367883.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!