to calculate:last digit of a^c

(a can be upto 1000 digits and c upto 18 digits)

plss… point out the fallacy in the code…

```
#include<iostream.h>
#include<math.h>
#include<string.h>
main()
{
int t,x,p,m,l,k,i;
unsigned long long s,r,c;
char a[1001];
cin>>t;
while(t--)
{
x=c=0;a[0]='\0';
gets(a);
l=strlen(a);
x=a[l-1]-48;
cin>>c;
if(!c)
cout<<"1\n";
else if(x==0||x==1||x==5||x==6)
cout<<x<<"\n";
else if(x==2||x==3||x==7||x==8)
{
r=c%4;
if(r==1||r==2||r==3)
p=pow(x,r);
else
p=pow(x,4);
cout<<p%10<<"\n";
}
else if(x==4||x==9)
{
s=c%2;
if(s)
m=pow(x,s);
else
m=pow(x,2);
cout<<m%10<<"\n";
}
}
return 0;
}
```