1 条题解
-
0
Pascal :
type arr=array[0..200]of longint; var i,j,k,m,n:longint; ans:arr; a,b,d,e:arr; s:string; function compare(k:longint):boolean; var i:longint; begin if a[k]=e[k] then exit(true); exit(false); end; function c(a,b:arr):arr; var i,j:longint; begin fillchar(c,sizeof(c),0); for i:=1 to a[0] do for j:=1 to b[0] do if i+j-1<=k then begin inc(c[i+j-1],(a[i]*b[j])mod 10); inc(c[i+j],(a[i]*b[j])div 10 +c[i+j-1] div 10); c[i+j-1]:=c[i+j-1] mod 10; end; c[0]:=k; while (c[c[0]]=0)and(c[0]>0) do dec(c[0]); end; function mul(k:longint):arr; var i,j:longint; begin fillchar(mul,sizeof(mul),0); for i:=1 to ans[0] do begin inc(mul[i],ans[i]*k); inc(mul[i+1],mul[i] div 10); mul[i]:=mul[i] mod 10; end; inc(mul[0],ans[0]+4); while (mul[mul[0]]=0)and(mul[0]<>0) do dec(mul[0]); end; begin ans[0]:=1; ans[1]:=1; readln(s); i:=pos(' ',s); for j:=i+1 to length(s) do k:=k*10+ord(s[j])-48; delete(s,i,length(s)-i+1); j:=0; for i:=length(s) downto 1 do begin inc(j); a[j]:=ord(s[i])-48; end; a[0]:=k; d:=a; e:=a; b[0]:=1; b[1]:=1; i:=1; j:=0; while true do begin if j>10 then begin writeln(-1); halt; end; inc(j); b:=c(b,d); a:=c(e,b); if compare(i) then begin d:=b; fillchar(b,sizeof(b),0); b[0]:=1; b[1]:=1; inc(i); ans:=mul(j); if i>k then break; j:=0; end; end; for i:=ans[0] downto 1 do write(ans[i]); end.
- 1
信息
- ID
- 241
- 时间
- 1000ms
- 内存
- 125MiB
- 难度
- (无)
- 标签
- 递交数
- 0
- 已通过
- 0
- 上传者