Cod sursa(job #54774)

Utilizator floreaflorea cristian florea Data 25 aprilie 2007 18:31:38
Problema Next Scor 30
Compilator fpc Status done
Runda Arhiva de probleme Marime 1.19 kb
var a,c:array[0..1000000]of byte;
    uc:integer;
    n:int64;
    i,j:longint;
    m,l,aux,aux2,rest:int64;
    s:ansistring;
    fi,fo:text;
procedure imp(k:integer);
begin
     j:=1;
     for i:=1 to m do
        begin
             aux:=aux*10+a[i];
             if aux>k then
                begin
                     c[j]:=aux div k;
                     rest:=aux mod k;
                     inc(j);
                     aux:=rest;
                end;
        end;
end;
procedure sum(k:integer);
begin
     aux2:=l;
     for i:=m downto 0 do
        begin
             aux2:=aux2+a[i];
             uc:=aux2 mod 10;
             c[i]:=uc;
             aux2:=aux2 div 10;
        end;
end;
begin
     assign(fi,'next.in'); reset(fi);
     assign(fo,'next.out'); rewrite(fo);
     readln(fi,s);
     c[0]:=0;
     for i:=1 to length(s) do
        val(s[i],a[i]);
     m:=length(s);
     readln(fi,n);
     aux:=0;
     imp(n);
     if aux=0 then for i:=1 to m do write(fo,a[i])
     else begin
     l:=n-aux;
     sum(l);
     if a[0]<>0 then write(fo,c[0]);
     for i:=1 to m do
        write(fo,c[i]);
        end;
     close(fi);
     close(fo);
end.