讨论 / pascal AC
潘崇明 2016-02-06 18:04:57
点我顶贴 收藏 删除
const max=100;

type hint=array[0..max] of longint;

var st,s1,s2:string;

k,ok:longint;

a:array[1..11] of hint;

b:array[0..9] of longint;

circle:array[0..max] of longint;

tot,n,start,sc,ss:hint;

i,j,ij,l,m:longint;

procedure multi(var a:hint;b,c:hint);

var i,j,e:longint;

begin

fillchar(a,sizeof(a),0);

for i:=0 to k-1 do

for j:=0 to k-1 do

if i+j<=k-1 then inc(a[i+j],b[i]*c[j]);

e:=0;

for i:=0 to k-1 do

begin

a[i]:=a[i]+e;

e:=a[i] div 10;

a[i]:=a[i] mod 10;

end;

end;

procedure mult(var a:hint;b:longint);

var i,e:longint;

begin

for i:=0 to a[max] do

a[i]:=a[i]*b;

e:=0;

for i:=0 to a[max]+1 do

begin

a[i]:=a[i]+e;

e:=a[i] div 10;

a[i]:=a[i] mod 10;

end;

if a[a[max]+1]>0 then a[max]:=a[max]+1;

end;

begin

assign(input,'circle.in');

reset(input);

assign(output,'circle.out');

rewrite(output);

readln(st);

s1:=copy(st,1,pos('',st)-1);

delete(st,1,pos('',st));

s2:=st;

delete(st,1,pos('',st)-1);

s2:=st;

while pos('',s2)>0 do

delete(s2,pos('',s2),1);

val(s2,k,ok);

s2:=copy(s1,length(s1)-k+1,k);

while length(s2)<k do

s2:='0'+s2;

for i:=1 to k do

n[k-i]:=ord(s2[i])-48;

n[max]:=k-1;

start:=n;

ss:=n;

a[1]:=n;

for i:=0 to k-1 do

begin

fillchar(b,sizeof(b),0);

b[a[1,i]]:=1;

j:=2;

while true do

begin

multi(a[j],a[j-1],ss);

if b[a[j,i]]=0

then begin

b[a[j,i]]:=j;

inc(j);

end

else begin

sc:=ss;

ij:=b[a[j,i]];

if ij<>1

then begin

writeln(-1);

close(input);

close(output);

halt;

end;

circle[i]:=j-1;

for ij:=2 to j-1 do

multi(ss,sc,ss);

j:=2;

break;

end;

end;

end;

fillchar(tot,sizeof(tot),0);

tot[0]:=1;

for i:=1 to k do

mult(tot,circle[i-1]);

for i:=k-1 downto 0 do

if tot[i]>0 then break;

for j:=i downto 0 do

write(tot[j]);

close(input);

close(output);

end.

#1 潘崇明@2016-02-06 18:21:10
回复 删除
这个是错的
查看更多回复
提交回复