LASTDIG2 - The last digit re-visited
#include <iostream>
using namespace std;
string s;
int main()
{
int t, i;
long long int a, b, d;
cin >> t;
while(t--)
{
cin >> s;
cin >> b;
i = s.size() - 1;
a = (s[i] - '0');
d = 1;
while(b)
{
if(b & 1)
{
d = (d * a) % 10;
}
a = (a * a) % 10;
b = b >> 1;
}
cout << d << endl;
}
return 0;
}
Comments
Post a Comment