Cod sursa(job #409488)

Utilizator C0Mr4d3yonootz321 C0Mr4d3 Data 3 martie 2010 18:13:28
Problema Cifra Scor 0
Compilator fpc Status done
Runda Arhiva de probleme Marime 1.85 kb
program cifra;
var f1,f2:text;
    t,i:word;
    n,j:longint;
    s:longint;
function uc(x:int64):byte;
var a:int64;
    s:word;
begin
  s:=0;
  a:=x;
  if x mod 10=1 then
    uc:=1
  else
    if x mod 10=2 then
      begin
        if a mod 4=0 then
          uc:=6
        else
          uc:=4;
      end
    else
      if x mod 10=3 then
        begin
          s:=0;
          repeat
            s:=s+x mod 10;
            x:=x div 10;
          until x=0;
          if s mod 2=0 then
            uc:=3
          else
            uc:=7;
        end
      else
        if (x mod 10=4) or (x mod 10=6) then
          uc:=6
        else
          if x mod 10=5 then
            uc:=5
          else
            if x mod 10=7 then
              begin
                s:=0;
                repeat
                  s:=s+x mod 10;
                  x:=x div 10;
                until x=0;
                if s mod 2=0 then
                  uc:=7
                else
                  uc:=3;
              end
            else
              if x mod 10=8 then
                begin
                  s:=0;
                  repeat
                    s:=s+x mod 10;
                    x:=x div 10;
                  until x=0;
                  if s mod 2=0 then
                    uc:=6
                  else
                    uc:=4;
               end
              else
                if x mod 10=9 then
                  uc:=9
                else
                  if x mod 10=0 then
                    uc:=0;
end;

begin
  assign(f1,'cifra.in');
  assign(f2,'cifra.out');
  reset(f1);
  rewrite(f2);
  readln(f1,t);
  for i:=1 to t do
    begin
      readln(f1,n);
      s:=0;
      for j:=1 to n do
        s:=s+uc(j);
      writeln(f2,s mod 10);
    end;
  close(f1);
  close(f2);
end.