[Mobius function] [bipartite] Bzoj 2440 perfect square

Description

X liked since childhood small number. The strange thing is, he is very annoying perfect square. He felt that these
number looks very uncomfortable. As a result, he hated all is the number of positive integer multiple of the number of full square. However,
this did not affect his love for the other numbers.
This day is a small X's birthday, I wanted to send a small number of W for him as a birthday gift. Of course, he could not send a
small number of X nasty. He lists all the small number of X is not hate, and then select the number of K gave
a small X. Small X very happy to accept it.
But now small W can not remember for the little X in which a number. Can you help him about it?

 

answer

  • Binary answer the question for the sake of converting [1, m] species square of the number of non-factor
  • No is not square factor μ (i)! = 0
  • The inclusion and exclusion, meet the requirements ans = n- only one prime factor is greater than the number of times equal to a + 2 only two prime factors equal to the number greater than 2 -...

 

Code

 1 #include <cmath>
 2 #include <cstdio>
 3 #include <iostream>
 4 #define ll long long
 5 using namespace std;
 6 const ll N=100010,inf=(1<<31)-1;
 7 ll T,n,l,r,ans,mobius[N],p[N],bz[N];
 8 bool check(ll x) { ll r=0; for (ll i=1;i<=sqrt(x);i++) r+=mobius[i]*x/(i*i); return r>=n; }
 9 int main()
10 {
11     scanf("%lld",&T),mobius[1]=1;
12     for (ll i=2;i<=N;i++)
13     {
14         if (!bz[i]) mobius[i]=-1,p[++p[0]]=i;
15         for (ll j=1;j<=p[0]&&i*p[j]<=N;j++)
16         {
17             bz[i*p[j]]=1;
18             if (i%p[j]) mobius[i*p[j]]=-mobius[i]; else { mobius[i*p[j]]=0; break; }
19         }
20     }
21     for (;T;T--)
22     {
23         scanf("%lld",&n),l=1,r=ans=inf;
24         while (l<=r)
25         {
26             ll mid=l+r>>1;
27             if (check(mid)) ans=mid,r=mid-1; else l=mid+1;
28         }
29         printf("%lld\n" , Year);
 30      }
 31 }

 

Guess you like

Origin www.cnblogs.com/Comfortable/p/11319506.html