Pagini recente » Cod sursa (job #1418944) | Cod sursa (job #2983566) | Cod sursa (job #1404779) | Cod sursa (job #1870546) | Cod sursa (job #38845)
Cod sursa(job #38845)
//infoarena next
const nrcif = 1000000;
type nrmare = array[0..nrcif] of longint;
var n:nrmare;
d:int64;
s:ansistring;
procedure strtonr(s:ansistring; var x:nrmare);
var i:longint;
coda:integer;
begin
x[0]:=length(s); coda:=ord('0');
for i:=length(s) downto 1 do
x[x[0]-i+1]:=ord(s[i])-coda;
end;
procedure citire;
begin
assign(input,'next.in'); reset(input);
readln(s); strtonr(s,n);
readln(d);
closE(input);
end;
procedure suma(var a:nrmare;b:nrmare);
var i:longint;
t:int64;
begin
i:=1;
t:=0;
while (i<=a[0]) or (i<=b[0]) or (t <>0 ) do
begin
t:=t div 10;
t:=t+a[i]+b[i];
a[i]:=t mod 10;
i:=i+1;
end;
a[0]:=i-2;
end;
function rest(x:nrmare; p:int64):int64;
var i:longint;
t:int64;
begin
i:=x[0];
t:=0;
while i > 0 do
begin
t:=(t * 10 + x[i]) mod p;
dec(i);
end;
rest:=t;
end;
procedure afis;
var i:longint;
begin
assign(output,'next.out'); rewrite(output);
for i:=n[0] downto 1 do
write(n[i]);
close(output);
end;
procedure calc;
var rr,rez:int64;
ss:ansistring;
aux:nrmare;
begin
rr:=rest(n,d);
rez:=(d-rr) mod d;
str(rez,ss);
fillchar(aux,sizeof(aux),0);
strtonr(ss,aux);
suma(n,aux);
afis;
end;
begin
citire;
calc;
end.