【BZOJ2440】完全平方数(莫比乌斯函数,容斥原理)
题意:求第k个无平方因子数
k<=10^9
思路:
感觉这东西和欧拉筛差不多……活到老学到老,退役前学点新知识也是好的
为什么二分答案的上界是2*n?连LYY都证不出来
话说约大爷一年之前就已经AC此题……%%%
1 const max=50000; 2 var mu,flag,prime:array[1..max]of int64; 3 cas,v,i,m,j,n:longint; 4 ans,l,r,mid,last,tmp:int64; 5 6 function clac(n:int64):int64; 7 var i:longint; 8 begin 9 clac:=0; 10 for i:=1 to trunc(sqrt(n)) do clac:=clac+mu[i]*n div (i*i); 11 end; 12 13 begin 14 assign(input,'bzoj2440.in'); reset(input); 15 assign(output,'bzoj2440.out'); rewrite(output); 16 readln(cas); 17 mu[1]:=1; 18 for i:=2 to max do 19 begin 20 if flag[i]=0 then 21 begin 22 inc(m); prime[m]:=i; 23 mu[i]:=-1; 24 end; 25 j:=1; 26 while prime[j]*i<=max do 27 begin 28 flag[prime[j]*i]:=1; 29 if i mod prime[j]=0 then 30 begin 31 mu[prime[j]*i]:=0; 32 break; 33 end; 34 mu[prime[j]*i]:=-mu[i]; 35 inc(j); 36 end; 37 end; 38 for v:=1 to cas do 39 begin 40 readln(n); 41 l:=1; r:=2*n; last:=1; 42 while l<=r do 43 begin 44 mid:=(l+r)>>1; 45 tmp:=clac(mid); 46 if tmp=n then begin last:=mid; r:=mid-1; end 47 else if tmp<n then l:=mid+1 48 else r:=mid-1; 49 end; 50 writeln(last); 51 end; 52 close(input); 53 close(output); 54 end.
null