Pagini recente » Cod sursa (job #2770279) | Cod sursa (job #13387) | Cod sursa (job #3133715) | Cod sursa (job #2252721) | Cod sursa (job #41755)
Cod sursa(job #41755)
const
lim=1000010;
base=10;
var
a:array[1..lim] of byte;
l,b,t:int64;
n:longint;
m,i,j:longint;
r:integer;
c:char;
procedure add;
begin
for i:=1 to (m div 2) do
begin
l:=a[i];
a[i]:=a[m-i+1];
a[m-i+1]:=l;
end;
i:=0;
while t>0 do
begin
inc(i);
t:=t+a[i];
a[i]:=t mod base;
t:=t div base;
end;
if i>m then m:=i;
end;
procedure divide;
begin
t:=0; i:=0;
while (t<b)and (i<m) do
begin
inc(i);
t:=t*base+a[i];
end;
n:=0;
while (i<=m) do
begin
if t>=b then t:=t mod b;
if (t<b) and (i<m) then
begin
inc(i);
t:=t*base+a[i];
end
else
if i=m then i:=m+2;
end;
if t>0 then t:=b-t;
add;
end;
begin
assign(input,'next.in');
reset(input);
m:=0;
while not eoln do
begin
read(c);
val(c,j,r);
inc(m);
a[m]:=j;
end;
readln;
readln(b);
{for i:=1 to (m div 2) do
begin
t:=a[i];
a[i]:=a[m-i+1];
a[m-i+1]:=t;
end; }
close(input);
divide;
assign(output,'next.out');
rewrite(output);
for i:=m downto 1 do write(a[i]);
close(output);
end.