<快速幂模> N^N的末尾数字

来源:互联网 发布:数组合并 js concat 编辑:程序博客网 时间:2024/06/05 07:56

链接:https://www.51nod.com/onlineJudge/questionCode.html#!problemId=1004

快速幂模板。。。

<span style="font-size:24px;">#include <cstdio>#include <algorithm>#include <iostream>#include <cstring>using namespace std;#define LL long longLL mod_pow(LL a, LL b, LL p){    LL ans = 1;    while(b > 0)    {        if(b & 1) ans = (ans * a )  % p;        a = (a * a) % p;        b >>= 1;    }    return ans;}int main(){    LL n;    while(cin>>n)    {        cout << mod_pow(n, n, 10) << endl;    }    return 0;}</span>


0 0
原创粉丝点击