Cod sursa(job #524467)

Utilizator richforthegunioana ghita richforthegun Data 21 ianuarie 2011 17:45:22
Problema Cifra Scor 0
Compilator fpc Status done
Runda Arhiva de probleme Marime 1.43 kb
type sir =array[1..100] of integer;
var x:sir;
i,n,z,j:integer;
f,g:text;
FUNCTION fact(n:integer):integer;
var c,p,cp:integer;
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.