HDOJ_1061_Rightmost Digit

AC代码:

#include <iostream>
#include <cstdio>
using namespace std;

int mod_exp(long long a,long long b,int m)
{
    int temp=1;
    a=a%m;
    while(b)
    {
        if(b%2==1)
            temp=temp*a%m;
        a=a*a%m;
        b>>=1;
    }
    
    return temp;
}

int main(void)
{
    freopen("in.txt","r",stdin);
    long long T;
    scanf("%lld",&T);
    while(T--)
    {
        long long n;
        int temp,m=10;
        scanf("%lld",&n);
        temp=mod_exp(n,n,m);
        
        printf("%d\n",temp);
    }
    fclose(stdin);
    return 0;
}

 

posted @ 2018-11-30 20:06  pha创噬  阅读(102)  评论(0编辑  收藏  举报