Pagini recente » Borderou de evaluare (job #103652) | Profil tudorbuhnia | Cod sursa (job #2194549) | Cod sursa (job #1682080) | Cod sursa (job #38862)
Cod sursa(job #38862)
//infoarena next
const nrcif = 1000000;
type nrmare = array[0..nrcif] of integer;
nrmic = array[0..100] of integer;
var n:nrmare;
aux:nrmic;
d:int64;
s:ansistring;
lungn,lungaux:longint;
procedure strtonr(var s:ansistring);
var i:longint;
coda:integer;
begin
lungn:=length(s); coda:=ord('0');
for i:=length(s) downto 1 do
n[lungn-i+1]:=ord(s[i])-coda;
end;
procedure strtonrmic(var s:ansistring);
var i:longint;
coda:integer;
begin
lungaux:=length(s); coda:=ord('0');
for i:=length(s) downto 1 do
aux[lungaux-i+1]:=ord(s[i])-coda;
end;
procedure citire;
begin
assign(input,'next.in'); reset(input);
readln(s); strtonr(s); s:='';
readln(d);
closE(input);
end;
procedure suma(var b:nrmic);
var i:longint;
t:int64;
begin
i:=1;
t:=0;
while (i<=lungn) or (i<=lungaux) or (t <>0 ) do
begin
t:=t div 10;
t:=t+n[i];
if i < 100 then t:=t+b[i];
n[i]:=t mod 10;
i:=i+1;
end;
lungn:=i-2;
end;
function rest(p:int64):int64;
var i:longint;
t:int64;
begin
i:=lungn;
t:=0;
while i > 0 do
begin
t:=(t * 10 + n[i]) mod p;
dec(i);
end;
rest:=t;
end;
procedure afis;
var i:longint;
begin
assign(output,'next.out'); rewrite(output);
for i:=lungn downto 1 do
write(n[i]);
close(output);
end;
procedure calc;
var rr,rez:int64;
ss:ansistring;
begin
rr:=rest(d);
rez:=(d-rr) mod d;
str(rez,ss);
fillchar(aux,sizeof(aux),0);
strtonrmic(ss);
suma(aux);
afis;
end;
begin
citire;
calc;
end.