LASTDIG - The last digit
#include <iostream>
#define ll long long int
using namespace std;
ll expo(ll a, ll b, int n)
{
ll d = 1;
while(b)
{
if((b & 1))
{
d = (d * a) % n;
}
b = b >> 1;
a = (a * a) % n;
}
return d;
}
int main()
{
int t;
ll a, b;
cin >> t;
while(t--)
{
cin >> a >> b;
cout << expo(a, b, 10) << endl;
}
return 0;
}
Comments
Post a Comment