#include <iostream> #include <cmath> typedef long long int ll; using namespace std; int main() { int t; ll a,b,rem,res; cin>>t; while(t--){ cin>>a>>b; rem = b%a; res = pow(a,rem+1); res = res%10; cout<<res<<endl; } return 0; }
I have given the explanation that will solve your problem already. Refer https://discuss.codechef.com/t/my-solution-for-the-last-digit-lastdig-got-accepted-in-codechef-but-not-getting-accepted-on-spoj/49361/4?u=striker22