• [hdu6428]Problem C. Calculate


    题目大意:有$T(1leqslant Tleqslant 10)$组数据,每组数据给你$A,B,C(0<A,B,Cleqslant 10^7)$,求$sumlimits_{i=1}^Asumlimits_{j=1}^Bsumlimits_{k=1}^Cvarphi((i,j^2,k^3))mod 2^{30}$

    题解:
    $$
    def dsum{displaystylesumlimits}
    egin{align*}
    &dsum_{i=1}^Adsum_{j=1}^Bdsum_{k=1}^Cvarphi((i,j^2,k^3))\
    =&dsum_{d=1}^Avarphi(d)dsum_{i=1}^Adsum_{j=1}^Bdsum_{k=1}^C[(i,j^2,k^3)=d]\
    end{align*}
    $$

    $$
    def dsum{displaystylesumlimits}
    令f(x)=dsum_{i=1}^Adsum_{j=1}^Bdsum_{k=1}^C[(i,j^2,k^3)=x]\
    egin{align*}
    F(x)&=dsum_{x|p}f(p)\
    &=dsum_{i=1}^Adsum_{j=1}^Bdsum_{k=1}^C[x|(i,j^2,k^3)]\
    &=dsum_{i=1}^A[x|i]dsum_{j=1}^B[x|j^2]dsum_{k=1}^C[x|j^3]\
    &莫比乌斯反演得:\
    f(x)&=dsum_{x|k}mu(dfrac k x)F(k)\
    &=dsum_{i=1}^Amu(i)F(ix)\
    ans&=dsum_{d=1}^Avarphi(d)dsum_{i=1}^Amu(i)F(id)\
    &=dsum_{T=1}^AF(T)dsum_{d|T}varphi(d)mu(dfrac T d)\
    &由狄利克雷卷积得:\
    ans&=dsum_{T=1}^AF(T)(mu*varphi)(d)
    end{align*}
    $$

    $$
    狄利克雷卷积得(mu*varphi)(d)为积性函数\
    def dsum{displaystylesumlimits}
    令g(x)=dsum_{d|T}mu(d)varphi(dfrac T d)\
    egin{align*}
    g(1)&=1\
    g(p)&=mu(1)varphi(p)+mu(p)varphi(1)\
    &=1cdot(p-1)+(-1)cdot1\
    g(p^k)&=mu(1)varphi(p^k)\
    &+mu(p)varphi(p^{k-1})\
    &qquadvdots\
    &+mu(p^k)varphi(1)\
    ecause&mu(p^k)当kgeqslant2时为0\
    herefore g(p^k)&=mu(1)varphi(p^k)+mu(p)varphi(p^{k-1})\
    &=p^k-k^{k-1}-(p^{k-1}-p^{k-2})\
    &=p^k-2p^{k-1}+p^{k-2}\
    herefore g(p^k)&=
    egin{cases}
    1(k=0)\
    p-2(k=1)\
    (p-1)^2(k=2)\
    pcdot g(p^{k-1})(kgeqslant2)\
    end{cases}
    end{align*}\
    可以用线性筛来做
    $$

    $$
    def dsum{displaystylesumlimits}
    def dprod{displaystyleprodlimits}
    F(x)=dsum_{i=1}^A[x|i]dsum_{j=1}^B[x|j^2]dsum_{k=1}^C[x|j^3]\
    易得dsum_{i=1}^A[x|i]=leftlfloordfrac A x ight floor\
    考虑dsum_{j=1}^B[x|j^2]:\
    对x分解质因数\
    令x=dprod p_i^{c_i}\
    令y_2(x)=dprod p_i^{leftlceildfrac{c_i}{2} ight ceil}\
    x|j^2Rightarrow[y_2(x)|j]\
    herefore dsum_{j=1}^B[x|j^2]=leftlfloordfrac{B}{y_2(x)} ight floor\
    同理,令y_3(x)=dprod p_i^{leftlceildfrac{c_i}{3} ight ceil}\
    herefore dsum_{k=1}^C[x|j^3]=leftlfloordfrac{B}{y_3(x)} ight floor\
    herefore F(x)=leftlfloordfrac A x ight floorleftlfloordfrac{B}{y_2(x)} ight floorleftlfloordfrac{B}{y_3(x)} ight floor\
    y_2(x),y_3(x)都可以线性筛
    $$

    卡点:

    C++ Code:

    #include <cstdio>
    #define maxn 10000010
    #define mod 1073741823
    int Tim, A, B, C;
    int pl[maxn], ptot, g[maxn], f2[maxn], f3[maxn];
    int cnt[maxn];
    bool isp[maxn];
    inline int sqr(int x) {return x * x;}
    void sieve(int n) {
    	g[1] = f2[1] = f3[1] = 1;
    	for (int i = 2; i < n; i++) {
    		if (!isp[i]) {
    			pl[ptot++] = i;
    			g[i] = i - 2;
    			f2[i] = f3[i] = i;
    			cnt[i] = 1;
    		}
    		for (int j = 0; j < ptot && pl[j] * i < n; j++) {
    			int t = pl[j] * i;
    			isp[t] = true;
    			if (i % pl[j] == 0) {
    				cnt[t] = cnt[i] + 1;
    				int p = i / pl[j];
    				if (p % pl[j]) g[t] = g[p] * sqr(pl[j] - 1);
    				else g[t] = g[i] * pl[j];
    				f2[t] = f2[i] * (cnt[t] & 1 ? pl[j] : 1);
    				f3[t] = f3[i] * (cnt[t] % 3 == 1 ? pl[j] : 1);
    				break;
    			}
    			cnt[t] = 1;
    			g[t] = g[i] * g[pl[j]];
    			f2[t] = f2[i] * f2[pl[j]];
    			f3[t] = f3[i] * f3[pl[j]];
    		}
    	}
    }
    int main() {
    	sieve(maxn);
    	scanf("%d", &Tim);
    	while (Tim --> 0) {
    		scanf("%d%d%d", &A, &B, &C);
    		int ans = 0;
    		for (int i = 1; i <= A; i++) ans += g[i] * (A / i) * (B / f2[i]) * (C / f3[i]);
    		printf("%d
    ", ans & mod);
    	}
    	return 0;
    }
    

      

  • 相关阅读:
    金融系列4《PUTKEY指令》
    数据分析≠Hadoop+NoSQL,不妨先看完善现有技术的10条捷径(分享)
    ASP.NET对HTML元素进行权限控制(三)
    ASP.NET对HTML元素进行权限控制(二)
    ASP.NET对HTML元素进行权限控制(一)
    作弊控制——心态
    SQL多表连接
    ASP.NET Repeater嵌套Repeater实现菜单加载
    ASP.NET从数据库中取出数据,有数据的复选框为选中
    ASP.NET——拒绝访问。 (异常来自HRESULT:0x80070005 (E_ACCESSDENIED))
  • 原文地址:https://www.cnblogs.com/Memory-of-winter/p/9681133.html
Copyright © 2020-2023  润新知