hdu1061Rightmost Digit

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

快速幂模板题

#include <cstdio>

const int mod = 1e5;

typedef long long ll;

ll quickAns(ll a,ll b)

{
    ll res = 1;
    while(b)
    {
        if(b & 1)
            res = (res * a) % mod ;
        a = (a * a) % mod;
        b >>= 1;
    }
    return res;
}

int main()

{
    int _;
    scanf("%d",&_);
    while(_--)
    {
       ll n;
       scanf("%lld",&n);
       ll ans = quickAns(n % mod,n % mod);
       printf("%d\n",ans % 10);
    }
    return 0;
}

你可能感兴趣的:(ACM,快速幂)