bzoj 1607: [Usaco2008 Dec]Patting Heads 轻拍牛头 暴力

用类似筛法的方法乱搞一下就好了。

代码:

var
  n,i,j,max:longint;
  a,s,f:array[1..1000000] of longint;
begin
  readln(n);
  for i:=1 to n do
  begin
    readln(a[i]);
    inc(s[a[i]]);
    if a[i]>max then max:=a[i];
  end;
  for i:=1 to max do
    if s[i]>0 then
      for j:=1 to max div i do
        f[i*j]:=f[i*j]+s[i];
  for i:=1 to n do
    writeln(f[a[i]]-1);
end.


你可能感兴趣的:(bzoj 1607: [Usaco2008 Dec]Patting Heads 轻拍牛头 暴力)