Cod sursa(job #222603)

Utilizator TrumpCardPopescu Silviu TrumpCard Data 23 noiembrie 2008 20:27:08
Problema Cifra Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.74 kb
#include <stdio.h>
#include <math.h>
int t;
long n;
int cifra(long x)
{int c=x%10;
switch (c) {
case 0: return 0;
case 1: return 1;
case 2: return (int)pow(2,x)%10;
case 3: return (int)pow(3,x)%10;
case 4: return (int)pow(4,x)%10;
case 5: return 5;
case 6: return 6;
case 7: return (int)pow(7,x)%10;
case 8: return (int)pow(8,x)%10;
case 9: return (int)pow(9,x)%10;
}}
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);
}