Cod sursa(job #524839)

Utilizator richforthegunioana ghita richforthegun Data 23 ianuarie 2011 12:48:58
Problema Cifra Scor 0
Compilator fpc Status done
Runda Arhiva de probleme Marime 1.42 kb
type sir =array[1..2000000] of longint;
var x:sir;
i,n,z,j:longint;
f,g:text;
FUNCTION fact(n:longint):longint;
var c,p,cp:longint;
begin
c:= n mod 10;
p:= n mod 100;
if c= 0 then cp:=0 else
if c=1 then cp:=1 else
if c=2 then if p=0 then cp:=1
else if p mod 4=1 then cp:=2
else if p mod 4=2 then cp:=4
else if p mod 4=3 then cp:=8
else if p mod 4=0 then cp:=6;

if c=3 then if p=0 then cp:=1
else if p mod 4=1 then cp:=3
else if p mod 4=2 then cp:=9
else if p mod 4=3 then cp:=7
else if p mod 4=0 then cp:=1;
if c=4  then if p=0 then cp:=1
else if p mod 2<>0 then cp:=4
else if p mod 2=0 then cp:=6;
if c=5 then if p=0 then cp:=1
               else cp:=5;
if c=6 then if p=0 then cp:=1
        else cp:=6;
if c=7 then if p=0 then cp:=1
else if p mod 4=1 then cp:=7
else if p mod 4=2 then cp:=9
else if p mod 4= 3 then cp:=3
else if p mod 4=0 then cp:=1;
if c=8 then if p=0 then cp:=1
else if p mod 4=1 then cp:=8
else if p mod 4=2 then cp:=4
else if p mod 4=3 then cp:=2
else if p mod 4=0 then cp:=6;
if c=9 then if p mod 1=0 then cp:=1
else if p=0 then cp:=1
else if p mod 2<>0 then cp:=9
else if p mod 2=0 then cp:=1;
fact:=cp;
end;
begin
assign(f,'cifra.in');reset(f);
assign(g,'cifra.out');rewrite(g);
readln(f,n);
for i:= 1 to n do
readln(f,x[i]);
for i:= 1 to n  do begin
  j:=0;
  for z:=1 to x[i] do
       j:=j+ fact(z);
   writeln(g,j mod 10);
   end;
   close(g);close(f);
end.