pascal解法2:
program circle;
type
num=record
p:byte;
n:array[1..100] of integer;
end;
var
can:boolean;
code,k,i,j:integer;
st:string;
n,n2:num;
f,a:array[0..100] of num;
now:array[0..10] of num;
function multiply(x,y:num;k:byte):num;
var
i,j:integer;
z:num;
begin
z.p:=x.p+y.p-1;
if z.p>k then z.p:=k;
fillchar(z.n,sizeof(z.n),0);
for i:=1 to y.p do
begin
z.n:=z.n+x.n[1]*y.n;
for j:=2 to x.p do
begin
if i+j-1>k then break;
z.n[i+j-1]:=z.n[i+j-1]+x.n[j]*y.n;
z.n[i+j-1]:=z.n[i+j-1]+z.n[i+j-2] div 10;
z.n[i+j-2]:=z.n[i+j-2] mod 10;
end;
end;
while (z.n[z.p]>=10)and(z.p<k) do
begin
inc(z.p);
z.n[z.p]:=z.n[z.p-1] div 10;
z.n[z.p-1]:=z.n[z.p-1] mod 10;
end;
z.n[z.p]:=z.n[z.p] mod 10;
multiply:=z;
end;
function same(x,y:num;k:byte):boolean;
var
i:integer;
begin
same:=false;
for i:=k downto 1 do
if x.n<>y.n then
exit;
same:=true;
end;
begin
assign(input,'circle.in');
reset(input);
readln(st);
close(input);
val(copy(st,pos(' ',st)+1,length(st)-pos(' ',st)),k,code);
delete(st,pos(' ',st),length(st)-pos(' ',st)+1);
n.p:=k;
fillchar(n.n,sizeof(n.n),0);
if length(st)>k then delete(st,1,length(st)-k);
for i:=1 to length(st) do
n.n:=ord(st[length(st)-i+1])-48;
f[0].p:=1;f[0].n[1]:=1;a[0]:=n;
f[k].p:=1;f[k].n[1]:=-1;
for i:=1 to k do
begin
fillchar(now,sizeof(now),0);
now[0]:=n;n2.p:=1;n2.n[1]:=1;can:=false;
for j:=1 to 10 do
begin
now[j]:=multiply(now[j-1],a[i-1],i);
n2:=multiply(n2,a[i-1],k);
if same(now[j],now[0],i) then
begin
a:=n2;
n2.p:=1;n2.n[1]:=j;
f:=multiply(f[i-1],n2,100);
can:=true;
break;
end;
end;
if not can then break;
end;
assign(output,'circle.out');
rewrite(output);
for i:=f[k].p downto 1 do write(f[k].n);
writeln;
close(output);
end.