2 条题解

  • 0
    @ 2025-10-8 17:10:04
    #include<bits/stdc++.h>
    #define ls(k) k << 1
    #define rs(k) k << 1 | 1
    #define fi first
    #define se second
    #define open(s1, s2) freopen(s1, "r", stdin), freopen(s2, "w", stdout);
    using namespace std;
    typedef __int128 __;
    typedef long double lb;
    typedef double db;
    typedef unsigned long long ull;
    typedef long long ll;
    bool Begin;
    const int N = 5e5 + 10, mod = 998244353;
    inline ll read(){
        ll x = 0, f = 1;
        char c = getchar();
        while(c < '0' || c > '9'){
            if(c == '-')
              f = -1;
            c = getchar();
        }
        while(c >= '0' && c <= '9'){
            x = (x << 1) + (x << 3) + (c ^ 48);
            c = getchar();
        }
        return x * f;
    }
    inline void write(ll x){
    	if(x < 0){
    		putchar('-');
    		x = -x;
    	}
    	if(x > 9)
    	  write(x / 10);
    	putchar(x % 10 + '0');
    }
    int Max, n, m, x, ans, inv2, cnt;
    int P[N], F[N], phi[N], mu[N], s[N];
    bool f[N];
    inline int qpow(int a, int b){
    	int ans = 1;
    	while(b){
    		if(b & 1)
    		  ans = 1ll * ans * a % mod;
    		a = 1ll * a * a % mod;
    		b >>= 1;
    	}
    	return ans;
    }
    void init(){
    	phi[1] = mu[1] = 1;
    	for(int i = 2; i <= Max; ++i){
    		if(!f[i]){
    			P[++cnt] = i;
    			mu[i] = -1;
    			phi[i] = i - 1;
    		}
    		for(int j = 1; j <= cnt && 1ll * i * P[j] <= Max; ++j){
    			f[i * P[j]] = 1;
    			if(i % P[j]){
    				phi[i * P[j]] = phi[i] * phi[P[j]];
    				mu[i * P[j]] = -mu[i];
    			}
    			else{
    				phi[i * P[j]] = phi[i] * P[j];
    				break;
    			}
    		}
    		mu[i] = (mu[i] + mod) % mod;
    	}
    	for(int d = 1; d <= Max; ++d)
    	  for(int n = d; n <= Max; n += d)
    	    F[n] = (F[n] + 1ll * (x % d) * mu[n / d] % mod) % mod;
    	for(int i = 1; i <= Max; ++i)
    	  s[i] = ((1ll * inv2 * phi[i] % mod - F[i] + mod) % mod + s[i - 1]) % mod;
    }
    bool End;
    int main(){
    	inv2 = qpow(2, mod - 2);
    	n = read(), m = read(), x = read();
    	Max = min(n, m);
    	ans = (1ll * n * m % mod * x % mod + 1ll * n * m % mod * (n + 1) % mod * (m - 1) % mod * qpow(8, mod - 2) % mod - 1ll * n * m % mod * (m + 1) % mod * qpow(4, mod - 2) % mod + mod) % mod;
    	init();
    	for(int l = 1, r; l <= Max; l = r + 1){
    		r = min(n / (n / l), m / (m / l));
    		ans = (ans + 1ll * (n / l) * (m / l) % mod * ((s[r] - s[l - 1] + mod) % mod) % mod) % mod;
    	}
    	write(ans);
    	cerr << '\n' << abs(&Begin - &End) / 1048576 << "MB";
    	return 0;
    }
    
    • 0
      @ 2025-10-8 17:09:47
       #include<bits/stdc++.h>
      #define ls(k) k << 1
      #define rs(k) k << 1 | 1
      #define fi first
      #define se second
      #define open(s1, s2) freopen(s1, "r", stdin), freopen(s2, "w", stdout);
      using namespace std;
      typedef __int128 __;
      typedef long double lb;
      typedef double db;
      typedef unsigned long long ull;
      typedef long long ll;
      bool Begin;
      const int N = 5e5 + 10, mod = 998244353;
      inline ll read(){
          ll x = 0, f = 1;
          char c = getchar();
          while(c < '0' || c > '9'){
              if(c == '-')
                f = -1;
              c = getchar();
          }
          while(c >= '0' && c <= '9'){
              x = (x << 1) + (x << 3) + (c ^ 48);
              c = getchar();
          }
          return x * f;
      }
      inline void write(ll x){
      	if(x < 0){
      		putchar('-');
      		x = -x;
      	}
      	if(x > 9)
      	  write(x / 10);
      	putchar(x % 10 + '0');
      }
      int Max, n, m, x, ans, inv2, cnt;
      int P[N], F[N], phi[N], mu[N], s[N];
      bool f[N];
      inline int qpow(int a, int b){
      	int ans = 1;
      	while(b){
      		if(b & 1)
      		  ans = 1ll * ans * a % mod;
      		a = 1ll * a * a % mod;
      		b >>= 1;
      	}
      	return ans;
      }
      void init(){
      	phi[1] = mu[1] = 1;
      	for(int i = 2; i <= Max; ++i){
      		if(!f[i]){
      			P[++cnt] = i;
      			mu[i] = -1;
      			phi[i] = i - 1;
      		}
      		for(int j = 1; j <= cnt && 1ll * i * P[j] <= Max; ++j){
      			f[i * P[j]] = 1;
      			if(i % P[j]){
      				phi[i * P[j]] = phi[i] * phi[P[j]];
      				mu[i * P[j]] = -mu[i];
      			}
      			else{
      				phi[i * P[j]] = phi[i] * P[j];
      				break;
      			}
      		}
      		mu[i] = (mu[i] + mod) % mod;
      	}
      	for(int d = 1; d <= Max; ++d)
      	  for(int n = d; n <= Max; n += d)
      	    F[n] = (F[n] + 1ll * (x % d) * mu[n / d] % mod) % mod;
      	for(int i = 1; i <= Max; ++i)
      	  s[i] = ((1ll * inv2 * phi[i] % mod - F[i] + mod) % mod + s[i - 1]) % mod;
      }
      bool End;
      int main(){
      	inv2 = qpow(2, mod - 2);
      	n = read(), m = read(), x = read();
      	Max = min(n, m);
      	ans = (1ll * n * m % mod * x % mod + 1ll * n * m % mod * (n + 1) % mod * (m - 1) % mod * qpow(8, mod - 2) % mod - 1ll * n * m % mod * (m + 1) % mod * qpow(4, mod - 2) % mod + mod) % mod;
      	init();
      	for(int l = 1, r; l <= Max; l = r + 1){
      		r = min(n / (n / l), m / (m / l));
      		ans = (ans + 1ll * (n / l) * (m / l) % mod * ((s[r] - s[l - 1] + mod) % mod) % mod) % mod;
      	}
      	write(ans);
      	cerr << '\n' << abs(&Begin - &End) / 1048576 << "MB";
      	return 0;
      }
      • 1

      *【莫比乌斯反演】BZOJ4174 tty 的求助

      信息

      ID
      5839
      时间
      1000ms
      内存
      512MiB
      难度
      10
      标签
      递交数
      2
      已通过
      1
      上传者