#include <iostream> using namespace std; int quickpower(int n) { int x = n; int answer = 1; while(x != 0){ if(x % 2 == 1){ answer = answer * n; answer = answer % 10; } x = x / 2; n = n * n; n = n % 10; } return answer; } int main() { int n; while (cin >> n){ cout << quickpower(n) << endl; } return 0; } |
Double click to view unformatted code.