i used recursion for this…and all test cases are showing correct output…but still getting WA…
My code:
#include<bits/stdc++.h>
#include
using namespace std;
int modulo(int a,long long int b,int m)
{
if(b==0)
return 1;
if(b%2==0)
{
int y=modulo(a,b/2,m);
return ((y%m)*(y%m))%m;
}
else
return (a%m)*modulo(a,b-1,m);
}
int main()
{
long long int b;
int a,t;
cin>>t;
while(t–)
{
cin>>a>>b;
int result=modulo(a,b,10);
cout<<result<<"\n";
}
return 0;
}