A - n^n的末位数字

给出一个整数N,输出N^N(N的N次方)的十进制表示的末位数字。

Input

一个数N(1 <= N <= 10^9)

Output

输出N^N的末位数字

Sample Input

13

Sample Output

3

(1)

#include<iostream> 
#include<stdio.h>
using namespace std;
typedef long long ll;
int a[20] = {1,4,7,6,5,6,3,6,9,0,1,6,3,6,5,6,7,4,9,0};
int main()
{
	ll n;
	scanf("%lld",&n);
    printf("%d", a[n%20-1]);
	return 0;
}

(2)

#include<iostream> 
#include<stdio.h>
using namespace std;
typedef long long ll;
int main()
{
	ll n;
	scanf("%lld",&n);
	int  ans=n%4;//末尾数字4次一循环 
	n=n%10;
	if(ans==0) cout<<n*n*n*n%10<<endl;
	else if(ans==1) cout<<n<<endl;
	else if(ans==2) cout<<n*n%10<<endl;
	else cout<<n*n*n%10<<endl;
	return 0;
}

猜你喜欢

转载自blog.csdn.net/qq_41555192/article/details/81987530