Du teach introductory title screen Detailed +

First look at big brother's blog

Here is the reasoning process, however, we need only remember the conclusions (function h, g, f are assumed, S is a prefix and function f):

 

Example 1: N = 1e10, find the formula

 

Ideas: S (i) f is a prefix and we want to find a g such that h prefix and good demand (h = f * g).

First write the equation h:

Then f set to u, we will find that that part is set in front of the nature of the Mobius:

So the band as a function g, f * g is equal to the membership function, and the function of the prefix meta 1 and not that right?

                 

Then we can be happy after simplification h into S (n) (also required by M (n)) in the equation:

Finally, the complexity is N 2/3 power ( I do not know why )

For the latter part can be clearly divisible block to seek attention code for: (sum of the f function and prefix)

int dfs(ll x)
{
    if(x<=N-5) return sum[x];
    if(mp[x]) return mp[x];//用map来记录是否已经计算过 
    ll ans=1;
    for(ll l=2,r;l>=0&&l<=x;l=r+1){//循环从2开始 
        r=x/(x/l);//*(r-l+1)是因为这个数重复了这么多次 
        ll xx=*(r-l+1)*dfs(x/l);
        ans=(ans-xx+mod)%mod;//注意要防止ans加成负数!! +mod %mod 
    }
    return mp[x]=ans;
}

例题2:N=1e10,求:

和上面一样,我们先写出h(n):   ,再把f当做:代入。

然后我们惊奇地发现,前面一部分不是可以用欧拉函数的性质替换吗?

现在只剩下了 d*g( n/d ),那g取什么呢?明显取id函数又可以快乐地把d抵消掉了! 最后h(n)=n^2。  (id函数:单位函数,id(n)=n)

ans的初始值是什么呢?前x的平方和式子是:n*(n+1)*(2n+1)/6。代码实现就仿照刚刚那个啦。

例题3:N=1e10,求

和上面的一样,自己动手推一下

好了经过一番推理之后,g也是同上题一样,也是取id函数的,下面是代码:

int dfs(ll x)
{
    if(x<=N-5) return sum[x];
    if(mp[x]) return mp[x];
    ll ans=1;
    for(ll l=2,r;l>=0&&l<=x;l=r+1){
        r=x/(x/l);//*(r-l+1)是因为这个数重复了这么多次 
        ll xx=(l+r) %mod *inv2 %mod *(r-l+1) %mod *dfs(x/l) %mod;//注意要对2求逆元 
        //L+r/2是因为原式里面有i 所以跳过一个区间时要加上这个区间和 :(l+r)/2首项加末项除以二 
        ans=(ans-xx+mod)%mod;
    }
    return mp[x]=ans;
}

然后是一个式子化简的小技巧:

最后说说N的范围,N太小了会T,太大了也可能会T,最好取600万

可以写写的题:洛谷P4213,P3768

完结啦~~

 

 

 

 

 

 

 

 

 

Guess you like

Origin www.cnblogs.com/mowanying/p/11273028.html