Cod sursa(job #1489241)

Utilizator SilviuIIon Silviu SilviuI Data 20 septembrie 2015 20:18:21
Problema Cifra Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.67 kb
#include <stdio.h>
#include <cstring>
using namespace std;
int n,i,j,t[110],m,x,sol;
char s[200];
int expo(int x,int n)
{
    int sol=1;
    while (n>0) {
        if (n%2==1) sol=(sol*x)%10;
        x=(x*x)%10; n=n/2;
    }
    return sol;
}
int main() {
freopen("cifra.in","r",stdin);
freopen("cifra.out","w",stdout);
scanf("%d",&n); gets(s);
for (i=1;i<=99;i++) {
    sol=0;
    for (j=1;j<=i;j++) sol=(sol+expo(j,j))%10;
    t[i]=sol;
}
for (i=1;i<=n;i++) {
    gets(s+1); m=strlen(s+1); x=0;
    if (m<=2) {
        for (j=1;j<=m;j++) x=x*10+s[j]-48;
    } else  {
        x=s[m]-48; x=x+10*(s[m-1]-48);
    }
    printf("%d\n",t[x]);
}
return 0;
}