• 题解 P2834 【能力测验】


    [ans=sum_{i=1}^nsum_{j=1}^m(n;mod;i) imes(m;mod;j),i eq j ]

    我们假设

    [nleq m ]

    [egin{aligned} ans & =sum_{i=1}^nsum_{j=1}^m(n;mod;i) imes(m;mod;j),i eq j \ & =sum_{i=1}^{n}sum_{j=1}^m(n;mod;i) imes(m;mod;j)-sum_{i=1}^n(n;mod;i) imes(m;mod;i) \ & =sum_{i=1}^{n}sum_{j=1}^m(n-leftlfloordfrac{n}{i} ight floorcdot i) imes(m-leftlfloordfrac{m}{j} ight floorcdot j)-sum_{i=1}^n(n-leftlfloordfrac{n}{i} ight floorcdot i) imes(m-leftlfloordfrac{m}{i} ight floorcdot i) \ & =sum_{i=1}^{n}(n-leftlfloordfrac{n}{i} ight floorcdot i)sum_{j=1}^m(m-leftlfloordfrac{m}{j} ight floorcdot j)-sum_{i=1}^n(n-leftlfloordfrac{n}{i} ight floorcdot i) imes(m-leftlfloordfrac{m}{i} ight floorcdot i) \ & =sum_{i=1}^{n}(n-leftlfloordfrac{n}{i} ight floorcdot i)sum_{j=1}^m(m-leftlfloordfrac{m}{j} ight floorcdot j)-sum_{i=1}^n(ncdot m - icdot(leftlfloordfrac{n}{i} ight floorcdot m+leftlfloordfrac{m}{i} ight floorcdot n)+leftlfloordfrac{n}{i} ight floorleftlfloordfrac{m}{i} ight floor i^2) end{aligned} ]

    然后

    前面的等式先用数论分块算出j循环的值,然后第二次数论分块分i的值,从而将前面的等式算出来。

    后面的等式直接数论分块

    r = min(n / (n / l), m / (m / l));
    

    换个样子就可以分了。

    然后要用平方和公式,所以得先把2,6的逆元算出来

    [sum_{i=1}^ni^2=frac{icdot(i+1)cdot(2cdot i +1)}{6} ]

    剩下的就没什么了

    #include<cstdio>
    #define Starseven main
    #define ll long long
    const ll mod = 19940417;
    
    ll Add(ll l, ll r) {
    	ll re = 0, ny2 = 9970209;
    	re = (1 + r) * r % mod * ny2 % mod;
    	re %= mod;
    	l--;
    	re = (re - (l + 1) * l % mod * ny2 % mod) % mod;
    	re = (re + mod) % mod;
    	return re;
    }
    
    ll All(ll l, ll r) {
    	ll ny6 = 3323403;
    	ll re = 0;
    	re = r * (r + 1) % mod * ((2 * r + 1) % mod) % mod * ny6 % mod;
    	l--;
    	re = (re - (l * (l + 1) % mod *((2 * l + 1) % mod) % mod * ny6 % mod)) % mod;
    	re = (re + mod) % mod;
    	return re; 
    }
    
    int Starseven(void) {
    	ll n, m;
    	read(n);
    	read(m);
    	if(n > m) swap(n, m);
    	ll ans = 0, judge = 0;
    	for (ll l = 1, r; l <= m; l = r + 1) {
    		r = m / (m / l);
    		ll hack = (r - l + 1) * m % mod;
    		hack = (hack - (m / l) * Add(l, r) % mod) % mod;
    		hack = (hack + mod) % mod;
    		judge = (judge + hack) % mod;
    	} 
    	for (ll l = 1, r; l <= n; l = r + 1) {
    		r = n / (n / l);
    		ll hack = (r - l + 1) * n % mod;
    		hack = (hack - (n / l) * Add(l, r) % mod) % mod;
    		hack = (hack + mod) % mod;
    		hack = hack * judge % mod;
    		ans = (ans + hack) % mod;
    	}
    	for (ll l = 1, r; l <= n; l = r + 1) {
    		r = min(n / (n / l), m / (m / l));
    		ll hack = n * m % mod * (r - l + 1) % mod;
    		hack += (n / l) * (m / l) % mod * All(l, r) % mod;
    		hack %= mod;
    		ll a = m * (n / l) % mod, b = n * (m / l) % mod;
    		hack = (hack - Add(l, r) * (a + b) % mod) % mod;
    		hack = (hack + mod) % mod;
    		ans = (ans - hack) % mod;
    		ans = (ans + mod) % mod;
    	}
    	write(ans);
    	puts("");
    	return 0;	
    }
    
  • 相关阅读:
    hdu 3507 Print Article —— 斜率优化DP
    bzoj 1096 仓库建设 —— 斜率优化DP
    ORDER BY 高级用法之CASE WHEN
    union和union all 的区别
    Ubuntu 链接ln的使用:创建和删除符号链接
    python中set和frozenset方法和区别
    python之sys模块详解
    odoo 8.0 多核启用
    Odoo 中的widget
    Odoo 在 Ubuntu 环境下性能调优
  • 原文地址:https://www.cnblogs.com/starseven/p/13567948.html
Copyright © 2020-2023  润新知