BZOJ4174: tty的求助

BZOJ4174: tty的求助_第1张图片

分析

明天再补 大概

代码

#include 

typedef long long LL;

const int N = 500005;
const int MOD = 998244353;


int n,m,x,f[N],mu[N],tot,prime[N];
bool not_prime[N];

void get_prime(int n)
{
    mu[1] = 1;
    for (int i = 2; i <= n; i++)
    {
        if (!not_prime[i]) 
            prime[++tot] = i, mu[i] = -1;
        for (int j = 1; j <= tot && i * prime[j] <= n; j++)
        {
            not_prime[i * prime[j]] = -1;
            if (i % prime[j] == 0) 
                break;
            mu[i * prime[j]] = -mu[i];
        }
    }
}

int main()
{
    double r;
    scanf("%d%d%lf",&n,&m,&r);
    x = (int)r;
    get_prime(n);
    int ny2 = MOD - MOD / 2;
    int ans = (LL)((LL)n * (n + 1) % MOD * ny2 % MOD * m % MOD * (m - 1) % MOD * ny2 % MOD - (LL)n * m % MOD * (m + 1) % MOD * ny2 % MOD) * ny2 % MOD;
    for (int d = 1; d <= n; d++)
    {
        int s = 0;
        for (int i = d; i <= n; i += d) 
            (s += (LL)(n / i) * (m / i) % MOD * mu[i / d]) %= MOD;
        (ans += ((LL)s * d % MOD * (x / d) % MOD + (LL)s * d % MOD * ny2 % MOD) % MOD) %= MOD;
    }
    printf("%d",(ans + MOD) % MOD);
    return 0;
}

你可能感兴趣的:(莫比乌斯反演)