The Last Digit problem Spoj Solution

 #include <iostream>

using namespace std;

typedef long long l;

int main(){

l t;

cin>>t;

while(t--){

l a,b,r1,r2;

cin>>a>>b;

r1=a%10;

r2=b%4;

if(a==0){

cout<<"0"<<endl;

}

else if(b==0){

cout<<"1"<<endl;

}

else if(r1==1 || r1== 5 || r1==6 || r1==0){

cout<<r1<<endl;

}

else{

if(r2==1){

cout<<r1%10<<endl;

}

else if(r2==2){

cout<<(r1*r1)%10<<endl;

}

else if(r2==3){

cout<<(r1*r1*r1)%10<<endl;

}

else 

cout<<(r1*r1*r1*r1)%10<<endl;

}

}

}


Comments

Popular posts from this blog

Factorials problem spoj Solution

Adding Reversed Numbers Spoj Solutions