Cod sursa(job #2047678)

Utilizator mari2001Maria Ionescu mari2001 Data 25 octombrie 2017 09:42:48
Problema Cifra Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.5 kb
#include<cstdio>
#include<cstring>
int v[105];
char ch[105];
int pow(int b,int e){
int p=1;
while(e){
if (e%2==1){
p=(p*b)%10;
e--;}
b=(b*b)%10;
e=e/2;}
return p;}
int main(){
freopen("cifra.in","r",stdin);
freopen("cifra.out","w",stdout);
int t,i1,n,i;
for(i=1;i<=99;i++)
v[i]=(v[i-1]+pow(i%10,i))%10;
scanf("%d\n",&t);
for(i1=1;i1<=t;i1++){
gets(ch+1);
n=strlen(ch+1);
if (n>1)
printf("%d\n",v[(ch[n-1]-'0')*10+ch[n]-'0']);
else
printf("%d\n",v[ch[n]-'0']);
scanf("\n");}
return 0;}