View Code of Problem 3696

#include<string>
#include<cstring>
#include<iostream>
using namespace std;
//快速幂算法
int main()
{
	int n;
	while (cin >> n)
	{
		int ans = 1;
		int temp = n;
		n %= 10;
		while (temp)
		{
			if (temp % 2 == 1)
				ans =(ans*n)%10;
			temp /= 2;
			n = n * n % 10;
		}
		cout << ans << endl;
	}
}

Double click to view unformatted code.


Back to problem 3696