#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.