Created
September 15, 2018 08:34
-
-
Save completejavascript/eb336f050d80dd1dc6dcaeed97dcd621 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
using namespace std; | |
int power(int a, int b) | |
{ | |
if (b == 0) return 1; | |
if(b % 2 == 0) | |
{ | |
int t = power(a, b/2); | |
return t*t; | |
} | |
else | |
{ | |
int t = power(a, (b - 1) / 2); | |
return t*t*a; | |
} | |
} | |
int main() | |
{ | |
ios::sync_with_stdio(false); | |
freopen("input.txt","r",stdin); | |
int T; | |
unsigned int a, b; | |
int last_digit; | |
cin >> T; | |
for(int tc = 0; tc < T; tc++) | |
{ | |
cin >> a >> b; | |
if(b == 0) last_digit = 1; | |
else | |
{ | |
int x = a % 10; | |
int y = b % 4; | |
if (y == 0) y = 4; | |
last_digit = power(x, y) % 10; | |
} | |
cout << last_digit << endl; | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment