View Code of Problem 3696

#include<iostream>
using namespace std;
int main(){
	int N;
	while(scanf("%d",&N)!=EOF){
		int res=N;
		int x=N;
		x=x%10;
		int result=1;
		while(res!=0){
			if(res%2==1){
				result*=x;
				result%=10;
			}
			res/=2;
			x*=x;
			x=x%10;
		}
		printf("%d\n",result);
	}
}

Double click to view unformatted code.


Back to problem 3696