View Code of Problem 3696

#include<string>
#include<cstring>
#include<iostream>
#include<cstdio>
using namespace std;
//快速幂算法
int main()
{
	int n;
	while (scanf("%d",&n)!=EOF)
	{
		int ans = 1;
		int temp = n;
		n %= 10;
		while (temp)
		{
			if (temp % 2 == 1)
			{
				ans *= n;
				ans %= 10;
			}
			temp /= 2;
			n *= n;
			n %= 10;
		}
		printf("%d\n", ans);
	}
}

Double click to view unformatted code.


Back to problem 3696