HDU 1061 Rightmost Digit( 快速幂水 )


**链接:****传送门 **

题意:求 N^N 的个位

思路:快速幂水题


/*************************************************************************
    > File Name: hdu1061.cpp
    > Author:    WArobot 
    > Blog:      http://www.cnblogs.com/WArobot/ 
    > Created Time: 2017年05月17日 星期三 22时50分05秒
 ************************************************************************/

#include<bits/stdc++.h>
using namespace std;

const int MOD = 10;
#define ll long long
#define mod(x) ((x)%MOD)
ll quick_mod(ll a,ll x){
	ll ret = 1;
	while(x){
		if(x&1)	ret = mod(ret*a);
		a = mod(a*a);
		x >>= 1;
	}
	return mod(ret);
}
int main(){
	ll t , n;
	scanf("%lld",&t);
	while(t--){
		scanf("%lld",&n);
		printf("%lld
",quick_mod(n,n));
	}
	return 0;
}
原文地址:https://www.cnblogs.com/WArobot/p/6870007.html