Luo Gu $ P4318 $ perfect square-half of inclusion and exclusion +

Correct answer: Yo斥 / Mori Christian 筛 + bisection

Report problem solving:

Portal $ QwQ $

First, a look at this data range is obviously considered half this number and then calculates $ $ Check number which is not less annoying incorrect number.

So consider how to count the number of the number of hate?

I hate to see this number that is not a multiple of the number of fully squared, not difficult to think can be understood as the absence of the prime factorization of $ x $ index greater than 1.

Other times equal to 0 to $ \ pm 1 $ naturally during this time can think of Mobius function? Because by definition have only prime number greater than 1.

So the answer is $ \ sum (\ mu (i)) ^ 2 $. Du teach sieve like (because I do not teach Du screen, so the sentence passed with $ kk $, so I could learn DU teach screen will come up pot lying ,,? $ QwQ $

Receiving method considering two-repellent, i.e., the answer = Total - a quality factor of the square of the multiples + multiple of the square of two different prime factors - the square of the multiples of three distinct prime factors ...

I do not explain the $ jio $ lie was quite clear that the $ QwQ $

Consider how find it? Again thought of the special nature of the Mobius function, consider this enumeration of the square root of $ i $, apparently contribution to $ \ frac {n} {i ^ 2} $. Consider coefficient? Found that the coefficient depends on the quality factor parity number, according to the definition still have Möbius function, the number of prime factors is a negative odd number, an even number of prime factors is a positive. number and quality factor which is greater than or equal to 0 guarantee a some are different prime factors.

In summary, the answer can be obtained $ ans = \ sum_ {i = 1} ^ {i ^ 2 \ leq n} \ mu (i) \ cdot \ frac {n} {i ^ 2} $

$over$?

 

#include<bits/stdc++.h>
using namespace std;
#define il inline
#define fi first
#define sc second
#define gc getchar()
#define mp make_pair
#define int long long
#define P pair<int,int>
#define ri register int
#define rc register char
#define rb register bool
#define rp(i,x,y) for(ri i=x;i<=y;++i)
#define my(i,x,y) for(ri i=x;i>=y;--i)
#define e(i,x) for(ri i=head[x];i;i=edge[i].nxt)

const int N=1e6+10;
int n,m,miu[N],pr[N],pr_cnt;
bool is_pr[N];

il int read()
{
    rc ch=gc;ri x=0;rb y=1;
    while(ch!='-' && (ch>'9' || ch<'0'))ch=gc;
    if(ch=='-')ch=gc,y=0;
    while(ch>='0' && ch<='9')x=(x<<1)+(x<<3)+(ch^'0'),ch=gc;
    return y?x:-x;
}
il void pre()
{
    miu[1]=1;
    rp(i,2,N-10)
    {
        if(!is_pr[i])pr[++pr_cnt]=i,miu[i]=-1;
        rp(j,1,pr_cnt)
        {
            if(i*pr[j]>N-10)break;;is_pr[i*pr[j]]=1;
            if(!(i%pr[j])){miu[i*pr[j]]=0;break;}
            miu[i*pr[j]]=-miu[i];
        }
    }
}
il int check(ri x)
{
    ri ret=0;
    for(ri i=1;i*i<=x;++i)ret+=miu[i]*(x/i/i);
    return ret;
}

signed main()
{
    //freopen("4318.in","r",stdin);freopen("4318.out","w",stdout);
    ri T=read();pre();
    while(T--)
    {ri K=read(),l=1,r=K<<1;while(l<r){ri mid=(l+r)>>1;if(check(mid)>=K)r=mid;else l=mid+1;}printf("%lld\n",l);}
    return 0;
}
View Code

 

 

 

Guess you like

Origin www.cnblogs.com/lqsukida/p/11600958.html