View Code of Problem 3696

#include <iostream>
using namespace std;
int main(){
	int n;
	while(cin>>n){
		if(n==0){
			cout<<1<<endl;
			continue;
		}
		int k=n%10;
		if(k==0||k==1||k==5||k==6){
			cout<<k<<endl;
		}else{
			if(k==2){//2 4 8 6 
				int a[4]={6,2,4,8};
				cout<<a[n%4]<<endl;
			}else if(k==3){//3 9 7 1 
				int a[4]={1,3,9,7};
				cout<<a[n%4]<<endl;
			}else if(k==4){//4 6
				int a[2]={6,4};
				cout<<a[n%2]<<endl;
			}else if(k==7){//7 9 3 1
				int a[4]={1,7,9,3};
				cout<<a[n%4]<<endl;
			}else if(k==8){//8 4 2 6
				int a[4]={6,8,4,2};
				cout<<a[n%4]<<endl;
			}else{//9 1
				int a[2]={1,9};
				cout<<a[n%2]<<endl;
			}
		}
	}
	return 0;
}

Double click to view unformatted code.


Back to problem 3696