View Code of Problem 3696

#include <iostream>
using namespace std;
//int kuaisumi(int a,int b){
//	int answer = 1;
//	while(b){
//		if(b%2==1){
//			answer *= a;
//			answer %= 10; 
//		}
//		a = a*a;
//		b = b/2;
//		a = a%10;		
//	}
//	return answer; 
//}
int main(){
	int n;
	while(scanf("%d",&n)!=EOF){
		int ans = 1;
		int a = n%10,b=n;
		while(b){
			if(b%2==1){
				ans *= a;
				ans %= 10; 
			}
			a = a*a;
			b = b/2;
			a = a%10;		
		}
		cout<<ans<<endl;
	}
  	return 0
}
/*
Main.cc: In function 'int main()':
Main.cc:32:12: error: expected ';' before '}' token
    return 0
            ^
            ;
 }
 ~           
*/

Double click to view unformatted code.


Back to problem 3696