Cod sursa(job #30254)

Utilizator razvi9Jurca Razvan razvi9 Data 13 martie 2007 17:18:32
Problema Cifra Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.62 kb
#include<stdio.h>
int t,a[10][5]={{0,0,0,0,0},
                {1,1,1,1,1},
                {1,2,4,8,6},
                {1,3,9,7,1},
                {1,4,6,4,6},
                {1,5,5,5,5},
                {1,6,6,6,6},
                {1,7,9,3,1},
                {1,8,4,2,6},
                {1,9,1,9,1}};
long n,i;
int cif(long n)
{int c=1;
 for(i=2;i<=n;i++)
 {c=c+a[i%10][i%4==0 ? 4:i%4];
  c=c%10;}
 return c;}
int main()
{freopen("cifra.in","r",stdin);
 freopen("cifra.out","w",stdout);
 scanf("%d",&t);
 for(int j=1;j<=t;j++)
 {scanf("%ld",&n);
  printf("%d\n",cif(n));}
 fclose(stdout);
 return 0;}