View Code of Problem 3696

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll f(ll a,ll b,int mod){
	ll ret=1;
	a%=mod;
	while(b){
		if(b&1){
			ret=ret*a%mod;
		}
		a=a*a%mod;
		b>>=1;
	}
	return ret;
}
int main(){
	ll n;
	while(cin>>n){
		if(n==0){
			cout<<1<<endl;
			continue;
		}
		cout<<f(n,n,10)<<endl;
	} 
}

Double click to view unformatted code.


Back to problem 3696