记录编号 33738 评测结果 AAAAAAAAAA
题目名称 [金陵中学2007] 最优分解方案 最终得分 100
用户昵称 Gravatarreamb 是否通过 通过
代码语言 Pascal 运行时间 0.004 s
提交时间 2011-11-11 17:24:39 内存使用 1.26 MiB
显示代码纯文本
program best;
var
  ss,s,ans:ansistring;
  n,i,j,t,lx,ly,l:longint;
  data:array[1..1000]of longint;
  a,b,c:array[1..100000]of longint;
function mo(x,y:ansistring):ansistring;
var
  i,j:longint;
begin
  s:='';
  lx:=length(x);
  ly:=length(y);
  for i:=1 to lx+ly do
    c[i]:=0;
  for i:=lx downto 1 do
    a[lx-i+1]:=ord(x[i])-ord('0');
  for i:=ly downto 1 do
    b[ly-i+1]:=ord(y[i])-ord('0');
  for i:=1 to lx do
    for j:=1 to ly do
    begin
      c[i+j-1]:=c[i+j-1]+a[i]*b[j];
      c[i+j]:=c[i+j]+c[i+j-1]div 10;
      c[i+j-1]:=c[i+j-1]mod 10
    end;
  if c[lx+ly]>0 then
    l:=lx+ly
  else
    l:=lx+ly-1;
  for i:=l downto 1 do
    s:=s+chr(ord('0')+c[i]);
  exit(s)
end;
begin
  assign (input,'best.in');
  reset (input);
  assign (output,'best.out');
  rewrite (output);
    readln (n);
    if n=4 then
    begin
      writeln (4);
      close (input);
      close (output);
      halt
    end;
    for i:=2 to n do
    begin
      n:=n-i;
      inc(t);
      data[t]:=i;
      if n<=i then
        break
    end;
    if n=i then
    begin
      inc(data[t]);
      dec(n);
    end;
    for i:=t downto 1 do
    begin
      if n=0 then
        break;
      inc(data[i]);
      dec(n)
    end;
    ans:='1';
    for i:=1 to t do
    begin
      str(data[i],ss);
      ans:=mo(ss,ans);
    end;
    writeln (ans);
  close (input);
  close (output)
end.