hdu-1061(快速幂)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1061

思路:快速幂

#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
typedef long long LL;
const int MOD = 1e5;
LL f(LL a,LL b)
{
    LL res=1;
    while(b!=0)
    {
        if(b%2==1) res=res*a%MOD;
        a=a*a%MOD;
        b/=2;
    }
    return res;
}

int main(void)
{
    LL n;
    int t;
    scanf("%d",&t);
    while(t--)
    {
        scanf("%lld",&n);
        n=f(n,n)%10;
        printf("%d\n",n);
    }
    return 0;
}

 

posted @ 2018-10-07 20:32  麟阁  阅读(811)  评论(0编辑  收藏  举报