var
n,m,w:longint;
i,j:longint;
out:array[1..50000] of longint;
sta:array[1..50000] of longint;
procedure solve(n:longint);
begin
if n=0 then
exit;
solve(n div m);
for i:=1 to 15000 do
for j:=1 to 15000 do
if n mod m=0
then
sta[i+j-1]:=sta[i+j-1]+out[i]*out[j]
else
sta[i+j-1]:=sta[i+j-1]+out[i]*out[j]*m;
for i:=1 to 15000 do
begin
out[i]:=sta[i] mod 10;
sta[i+1]:=sta[i+1]+sta[i] div 10;
end;
for i:=1 to 15000 do sta[i]:=0;
end;
begin
assign(input,'cruel1.in');
assign(output,'cruel1.out');
reset(input);
rewrite(output);
readln(m,n);
out[1]:=1;
solve(n);
for i:=15000 downto 1 do
begin
if out[i]<>0 then
begin
write(out[i]);
w:=w+1;
end;
if (w mod 70=1)and(w<>1) then writeln;
end;
close(input);
close(output);
end.