# Rightmost Digit

#include<stdio.h>
int fun(a){
int c, n;
c = a%10;
switch(c)
{
case 0:
case 1:
case 5:
case 6:
case 9:
n = c;
break;
case 3:
if(a%4 == 1) n = 3;
else n = 7;
break;
case 4:
n = 6;
break;
case 7:
if(a%4 == 1) n = 7;
else n = 3;
break;
case 2:
case 8:
if(a%4 == 0) n = 6;
else n = 4;
break;
default: break;
}
return n;
}
int main()
{
int T, a, n;
scanf("%d", &T);
while(T--)
{
scanf("%d", &a);
printf("%d\n",fun(a));
}
return 0;
}


#include<stdio.h>
int main()
{
int T, a, n, i;
scanf("%d", &T);
while(T--)
{
scanf("%d", &a);
if((a%10) == 0) n = 0;  //末尾为0的数
else
{
n = 1;
if(!(a%4))  //以4为周期循环
i=4 ;
else
i = a%4;
while(i--)
n *= a;
}
printf("%d\n", n%10);
}
return 0;
}


#### 杭电 1061 Rightmost Digit计算N^N次方的最后一位

2011-09-27 22:19:35

#### ACM刷题之HDU————Rightmost Digit

2016-03-24 22:57:17

#### HDOJ-1061-Rightmost Digit (求n^n的最低位)

2010-01-22 23:12:00

#### HDU 1061 Rightmost Digit (快速幂取余)

2015-07-10 16:22:46

#### hdu oj 1061 Rightmost Digit （快速幂算法）

2015-01-17 10:55:39

#### Rightmost Digit & Leftmost Digit

2017-01-23 21:31:13

#### rightmost digit

2016-09-23 09:11:22

#### Rightmost digit

2012-02-29 20:32:12

#### Given a positive integer N, you should output the most right digit of N^N.

2016-06-30 11:28:40