Given a positive integer N, you should output the most right digit of N^N.
Input
The input contains several test cases. The first line of the input is a single integer T which is the number of test cases. T test cases follow.
Each test case contains a single positive integer N(1<=N<=1,000,000,000).
Output
For each test case, you should output the rightmost digit of N^N.
Sample Input
2
3
4
Sample Output
7
6
问题链接:https://vjudge.net/contest/275893#problem/G
问题简述:输入一个数n,输出n^n的尾数
问题分析:任何n^n的的尾数只与n的尾数和n/4的情况有关
程序说明:先判断n的尾数是多少,再求n是否大于4,n与4除于是多少,根据规律得从结果
AC通过的C++程序如下:
include<iostream>
using namespace std;
int main
{
int t, n, work,work1,time;
cin >> t;
for (int i = 0; i < t; i++)
{
cin >> n;
if(n<=10)
{
work = n;
}
else work = n % 10;
if (n >= 4)
{
time = n % 4 ;
}
else time = n;
if (work == 0 || work == 1 || work == 5 || work == 6)
{
cout << work << endl;
}
else
{
switch (time)
{
case 0:work1 = (work*work*work*work) % 10; break;
case 1:work1 = (work) % 10; break;
case 2:work1 = (work*work) % 10; break;
case 3:work1 = (work*work*work) % 10; break;
}
cout << work1 << endl;
}
}
return 0;
}