Cod sursa(job #37514)

Utilizator ProtomanAndrei Purice Protoman Data 25 martie 2007 10:42:21
Problema Next Scor 100
Compilator fpc Status done
Runda preONI 2007, Runda 4, Clasa a 9-a si gimnaziu Marime 0.8 kb
var f1,f2:text; d,x,aux:int64; i,j,n:longint; a:array[-20..1000000] of integer; c:char;
begin
        assign(f1,'next.in');
        reset(f1);
        assign(f2,'next.out');
        rewrite(f2);
        while not eoln(f1) do begin
                inc(i);
                read(f1,c);
                a[i]:=ord(c)-48;
                end;
        read(f1,d);
        n:=i;
        for i:=1 to n do begin
                x:=x*10+a[i];
                x:=x mod d;
        end;
        x:=(d-x)mod d;
        j:=n;
        while x>0 do begin
                aux:=(x+a[j]) div 10;
                a[j]:=(x+a[j]) mod 10;
                x:=aux;
                dec(j);
        end;
        if j>0 then j:=0;
        for i:=j+1 to n do write(f2,a[i]);
        close(f1);
        close(f2);
end.