//解题思路:求一个数最右边的一位数,即%10,
//故:N^N 的最右边的一位数是( N^N ) % 10,根据同余定理= (N % 10)^N
//通过观察由 1 - 9的 N 次幂容易找出相应的规律,
#include <iostream>
#include <algorithm>
using namespace std;
#include <stdlib.h>
int main ()
{
int t;
scanf ("%d", &t);
while ( t -- )
{
int n, a;
scanf ("%d", &n);
a = n % 10;
if ( a == 0 )
printf ("%d\n", 0);
else if ( a == 1 )
printf ("%d\n", 1);
else if ( a == 5 )
printf ("%d\n", 5);
else if ( a == 6 )
printf ("%d\n", 6);
else if ( a == 2 )
{
if ( n % 4 == 0 )
printf ("%d\n", 6);
else if ( n % 4 == 1 )
printf ("%d\n", 2);
else if ( n % 4 == 2 )
printf ("%d\n", 4);
else if ( n % 4 == 3 )
printf ("%d\n", 8);
}
else if ( a == 3 )
{
if ( n % 4 == 0 )
printf ("%d\n", 1);
else if ( n % 4 == 1 )
printf ("%d\n", 3);
else if ( n % 4 == 2 )
printf ("%d\n", 9);
else if ( n % 4 == 3 )
printf ("%d\n", 7);
}
else if ( a == 4 )
{
if ( n % 2 == 0 )
printf ("%d\n", 6);
else if ( n % 2 == 1 )
printf ("%d\n", 4);
}
else if ( a == 7 )
{
if ( n % 4 == 0 )
printf ("%d\n", 1);
else if ( n % 4 == 1 )
printf ("%d\n", 7);
else if ( n % 4 == 2 )
printf ("%d\n", 9);
else if ( n % 4 == 3 )
printf ("%d\n", 3);
}
else if ( a == 8 )
{
if ( n % 4 == 0 )
printf ("%d\n", 6);
else if ( n % 4 == 1 )
printf ("%d\n", 8);
else if ( n % 4 == 2 )
printf ("%d\n", 4);
else if ( n % 4 == 3 )
printf ("%d\n", 2);
}
else if ( a == 9 )
{
if ( n % 2 == 0 )
printf ("%d\n", 1);
else if ( n % 2 == 1 )
printf ("%d\n", 9);
}
}
system ("pause");
return 0;
}
posted on 2010-09-11 22:00
雪黛依梦 阅读(515)
评论(0) 编辑 收藏 引用 所属分类:
简单题 、
数论