Pagini recente » Cod sursa (job #2463714) | Cod sursa (job #296508) | Cod sursa (job #1112842) | Cod sursa (job #1712437) | Cod sursa (job #41746)
Cod sursa(job #41746)
const
lim=100005;
base=10;
var
a:array[1..lim] of int64;
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
begin
inc(n);
t:=t mod b;
end;
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;
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.