Cod sursa(job #222654)

Utilizator TrumpCardPopescu Silviu TrumpCard Data 24 noiembrie 2008 06:44:01
Problema Cifra Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.85 kb
#include <stdio.h>
#include <math.h>
int t;
long n;
int cifra(long x)
{int c=0;
switch (x%10) {
case 0: {c=0; break;}
case 1: {c=1; break;}
case 2: {if (((x%10)%10)%2==1) c=6;
         else c=4;
         break;}
case 3: {c=(int)pow(3,x%4)%10;
         break;}
case 4: {c=6;break;}
case 5: {c=5; break;}
case 6: {c=6; break;}
case 7: {c=(int)pow(7,x%4)%10;
         break;}
case 8: {if (((x%10)%10)%2==1) c=4;
         else c=6;
         break;}
case 9: {c=9;break;}
}
return c;}
int main()
{
freopen("cifra.in", "r", stdin);
freopen("cifra.out", "w", stdout);
scanf("%d", &t);
for(int i=0;i<t;i++) {scanf("%ld", &n);
                      int s=0;
                      for(int j=1;j<=n;j++) s+=cifra(j);
                      s=s%10;
                      printf("%d\n", s);
                      }
fclose(stdin);
fclose(stdout);
}