比赛 20120419x 评测结果 ATTWTTTTTT
题目名称 最长数列 最终得分 10
用户昵称 wo shi 刘畅 运行时间 0.000 s
代码语言 Pascal 内存使用 0.00 MiB
提交时间 2012-04-19 16:38:30
显示代码纯文本
var
  t,time,i,j,n:longint;
  ok:boolean;
  cha,now,ans,max:int64;
  a:array[0..100000]of int64;

procedure sort(l,r:longint);
var
  i,j:longint;
  x,y:int64;
begin
  i:=l;
  j:=r;
  x:=a[(l+r) div 2];
  repeat
    while a[i]<x do inc(i);
    while x<a[j] do dec(j);
    if i<=j then
    begin
      y:=a[i];
      a[i]:=a[j];
      a[j]:=y;
      inc(i);
      dec(j);
    end;
  until i>j;
  if i<r then sort(i,r);
  if l<j then sort(l,j);
end;

function mul(b,p:int64):int64;
var
  ans,t:int64;
begin
  ans:=1;
  t:=b;
  while p>0 do
  begin
    if p mod 2=1 then
    ans:=ans*t;
    if ans>maxlongint then exit(ans);
    t:=t*t;
    p:=p div 2;
  end;
  mul:=ans;
end;

procedure erfen(x:int64;l,r:longint);
var
  mid:longint;
begin
  if l=r then
  begin
    if a[l]=x then ok:=true;
    exit;
  end;
  mid:=(l+r) div 2;
  if x<=a[mid] then erfen(x,l,mid)
  else erfen(x,mid+1,r);
end;

function you(x:int64):boolean;
begin
  ok:=false;
  erfen(x,1,n);
  if ok then exit(true);
  exit(false);
end;

begin
  assign(input,'series.in'); reset(input);
  assign(output,'series.out'); rewrite(output);
  readln(t);
  for time:=1 to t do
  begin
    readln(n);
    for i:=1 to n do read(a[i]);
    sort(1,n);
    if n=1 then
    begin
      writeln(1);
      continue;
    end;
    max:=-maxlongint;
    now:=1;
    for i:=2 to n do
    if a[i]=a[i-1] then
    begin
      inc(now);
      if now>max then max:=now;
    end
    else now:=1;

    {1}
    for i:=1 to n do
     for j:=1 to n do
     if i<>j then
     begin
       cha:=a[j]-a[i];
       if cha=0 then break;
       now:=a[j];
       ans:=2;
       while you(now+cha) do
       begin
         now:=now+cha;
         inc(ans);
       end;
       if ans>max then max:=ans;
     end;

    {2}
    for i:=1 to n do
     for j:=1 to n do
     if (i<>j)and(a[i]<>0)and(a[j]<>0)and(a[j] mod a[i]=0) then
     begin
       cha:=a[j] div a[i];
       if cha=1 then break;
       now:=a[j];
       ans:=2;
       while you(now*cha) do
       begin
         now:=now*cha;
         inc(ans);
       end;
       if ans>max then max:=ans;
     end;

     {3}
     for i:=1 to n do
      for j:=1 to n do
      if (i<>j)and(a[i]>0)and(a[j]>0)and(a[i]<>1)
      and(trunc(ln(a[j])/ln(a[i]))=ln(a[j])/ln(a[i])) then
      begin
        cha:=trunc(ln(a[j])/ln(a[i]));
        if cha=0 then break;
        now:=a[j];
        ans:=2;
        while you(mul(now,cha)) do
        begin
          now:=mul(now,cha);
          if now>maxlongint then break;
          inc(ans);
        end;
        if ans>max then max:=ans;
      end;
      writeln(max);
  end;
  close(input);
  close(output);
end.