Gcd Product

观察式子,不难发现,二者对于给定的都是可以确定的,跟变量无关,

,得到

接下来我们考虑化简

,则,可得:

同余方程

,则,所以

,则,因为,所以有

所以,分别在膜下有且只有唯一解,有

可得,要使

相当于在的基础上给组合分配,凑得

,所以解的个数就是,则有:

先做一次迪利克雷卷积得到,再做一次互质迪利克雷卷积得到,最后迪利克雷卷积得到答案。

#include <bits/stdc++.h>

using namespace std;

const int N = 5e5 + 10, mod = 998244353;

int prime[N], mu[N], phi[N], A[N], B[N], f[N], g[N], h[N], ans[N], n, cnt;

bool st[N];

void init() {
  mu[1] = phi[1] = 1;
  for (int i = 2; i < N; i++) {
    if (!st[i]) {
      prime[++cnt] = i;
      mu[i] = mod - 1;
      phi[i] = i - 1;
    }
    for (int j = 1; j <= cnt && 1ll * i * prime[j] < N; j++) {
      st[i * prime[j]] = 1;
      if (i % prime[j] == 0) {
        phi[i * prime[j]] = phi[i] * prime[j];
        break;
      }
      phi[i * prime[j]] = phi[i] * (prime[j] - 1);
      mu[i * prime[j]] = mod - mu[i];
    }
  }
}

int main() {
  // freopen("in.txt", "r", stdin);
  // freopen("out.txt", "w", stdout);
  // ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  init();
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &A[i]);
  }
  for (int i = 1; i <= n; i++) {
    scanf("%d", &B[i]);
  }
  for (int i = 1; i <= n; i++) {
    for (int j = i; j <= n; j += i) {
      f[j] = (f[j] + 1ll * A[i] * mu[j / i] % mod) % mod;
      g[j] = (g[j] + 1ll * B[i] * mu[j / i] % mod) % mod;
    }
  }
  for (int i = 1; i <= n; i++) {
    for (int j = i; j <= n; j += i) {
      if (1ll * phi[i] * phi[j / i] == phi[j]) {
        h[j] = (h[j] + 1ll * f[i] * g[j / i] % mod) % mod;
      }
    }
  }
  for (int i = 1; i <= n; i++) {
    for (int j = i; j <= n; j += i) {
      ans[j] = (ans[j] + 1ll * (j / i) * h[i] % mod) % mod;
    }
  }
  for (int i = 1; i <= n; i++) {
    ans[i] ^= ans[i - 1];
  }
  printf("%d\n", ans[n]);
  return 0;
}