Cod sursa(job #281134)

Utilizator vladcfVlad Frasineanu vladcf Data 13 martie 2009 20:33:23
Problema Cifra Scor 0
Compilator fpc Status done
Runda Arhiva de probleme Marime 1.6 kb
var n,i,s,k,j:longint;
    f,g:text;
begin
assign(f,'cifra.in');
assign(g,'cifra.out');
reset(f);
rewrite(g);
readln (f,k);
for j:=1 to k do
begin
s:=0;
read (f,n);
for i:=1 to n do
    begin
     if i mod 10=1 then s:=s+1;
     if i mod 10=2 then
        begin
        if i mod 4=1 then
           s:=s+2;
        if i mod 4=2 then
           s:=s+4;
        if i mod 4=3 then
           s:=s+8;
        if i mod 4=0 then
           s:=s+6;
        end;
     if i mod 10=3 then
        begin
        if i mod 4=1 then
           s:=s+3;
        if i mod 4=2 then
           s:=s+9;
        if i mod 4=3 then
           s:=s+7;
        if i mod 4=0 then
           s:=s+1;
        end;
     if i mod 10=4 then
        begin
        if i mod 2=0 then
           s:=s+6;
        if i mod 2=1 then
           s:=s+4;
        end;
     if i mod 10=5 then s:=s+5;
     if i mod 10=6 then s:=s+6;
     if i mod 10=7 then
        begin
        if i mod 4=1 then
           s:=s+7;
        if i mod 4=2 then
           s:=s+9;
        if i mod 4=3 then
           s:=s+3;
        if i mod 4=0 then
           s:=s+1;
        end;
     if i mod 10=8 then
        begin
        if i mod 4=1 then
           s:=s+8;
        if i mod 4=2 then
           s:=s+4;
        if i mod 4=3 then
           s:=s+2;
        if i mod 4=0 then
           s:=s+6;
        end;
     if i mod 10=9 then
        begin
        if i mod 2=1 then
           s:=s+9
           else
           s:=s+1;
        end;
     s:=s mod 10;
    end;
writeln (g,s);
end;
close(f);
close(g);
end.