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
問題簡述:輸入一個數(shù)n饵溅,輸出n^n的尾數(shù)
問題分析:任何n^n的的尾數(shù)只與n的尾數(shù)和n/4的情況有關
程序說明:先判斷n的尾數(shù)是多少牙丽,再求n是否大于4寂恬,n與4除于是多少刃唤,根據(jù)規(guī)律得從結果
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;
}