标签:hdu
2 3 4
7 6HintIn the first case, 3 * 3 * 3 = 27, so the rightmost digit is 7. In the second case, 4 * 4 * 4 * 4 = 256, so the rightmost digit is 6.
#include <iostream> #include <algorithm> #include <cstdio> using namespace std; long long int powermod(long long int a,long long int b,long long int c) { long long int ans = 1; a = a%c; while (b > 0) { if (b% 2 ==1) ans = ans * a %c; b = b/2; a = a* a %c; } return ans; } int main() { int t; long long int n; cin >> t; while (t--) { cin >> n; cout <<powermod(n,n,10) << endl; } return 0; }
版权声明:本文为博主原创文章,未经博主允许不得转载。
标签:hdu
原文地址:http://blog.csdn.net/xiaotan1314/article/details/47090737