Rightmost Digit(求N^N的个位)

1、N个位为0,1,4,5,6,9时,N^N的个位分别为0,1,6,5,6,9。

2、N个位为其他数字时,根据N的十位奇偶性,N^N的个位只有2种情况。

#include<iostream>
using namespace std;

int main(){
	int N,T,N1,N2;
	cin >> T;
	while (T--){
		cin >> N;
		N1 = N % 10;
		N2 = N % 100 / 10;
		switch (N1)
		{
		case 0:cout << 0<<endl; break;
		case 1:cout << 1 << endl; break;
		case 2:if (N2 % 2 == 0) {
				   cout << 4 << endl; break;
		}
			   else{ cout << 6 << endl; break; }
		case 3:if (N2 % 2 == 0){
				   cout << 7 << endl; break;
		}
			   else{ cout << 3 << endl; break; }
		case 4:cout << 6 << endl; break;
		case 5:cout <<5 << endl; break;
		case 6:cout << 6 << endl; break;
		case 7:if (N2 % 2 == 0){
				   cout << 3 << endl; break;
		}
			   else{ cout << 7 << endl; break; }
		case 8:if (N2 % 2 == 0){
				   cout << 6 << endl; break;
		}
			   else{ cout << 4 << endl; break; }
		case 9:cout << 9 << endl; break;
		default:
			break;
		}
	}
	return 0;
}



你可能感兴趣的:(Rightmost Digit(求N^N的个位))