View Code of Problem 3696

#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int pow(int a, int b, int c) {
	int ans = 1;
	while (b) {
		if (b % 2 == 1) {
			ans =(ans*a)%c;
		}
		a = (a*a) % c;
		b /= 2;
	}
	return ans;
}
int main()
{
	int n;
	while (scanf("%d",&n)!=EOF) {
		int res = pow(n, n, 10);
		printf("%d\n", res);
	}

	return 0;
}

Double click to view unformatted code.


Back to problem 3696