luogu2522 [HAOI2011]Problem b

Posted poorpool

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了luogu2522 [HAOI2011]Problem b相关的知识,希望对你有一定的参考价值。

参考

#include <iostream>
#include <cstring>
#include <cstdio>
using namespace std;
typedef long long ll;
int n, mu[50005], pri[50005], cnt;
bool isp[50005];
int a, b, c, d, k;
ll q(int x, int y){
    int lst;
    ll ans=0;
    if(x>y) swap(x, y);
    for(int i=1; i<=x; i=lst+1){
        lst = min(x/(x/i), y/(y/i));
        ans += (mu[lst] - mu[i-1]) * (ll)(x/i) * (ll)(y/i);
    }
    return ans;
}
void solv(){
    a--; c--;
    a /= k; b /= k; c /= k; d /= k;
    printf("%lld\n", q(b, d)-q(a,d)-q(b,c)+q(a,c));
}
void shai(){
    memset(isp, true, sizeof(isp));
    isp[0] = isp[1] = false;
    mu[1] = 1;
    for(int i=2; i<=50000; i++){
        if(isp[i])  pri[++cnt] = i, mu[i] = -1;
        for(int j=1; j<=cnt; j++){
            if(i*pri[j]>50000)  break;
            isp[i*pri[j]] = false;
            if(i%pri[j]==0){
                mu[i*pri[j]] = 0;
                break;
            }
            mu[i*pri[j]] = -mu[i];
        }   
    }
    for(int i=2; i<=50000; i++) mu[i] += mu[i-1];
}
int main(){
    cin>>n;
    shai();
    while(n--){
        scanf("%d %d %d %d %d", &a, &b, &c, &d, &k);
        solv();
    }
    return 0;
}

以上是关于luogu2522 [HAOI2011]Problem b的主要内容,如果未能解决你的问题,请参考以下文章

luogu2522 [HAOI2011]Problem b

Luogu P2522 [HAOI2011]Problem b 莫比乌斯反演

P2522 [HAOI2011]Problem b

P2522 [HAOI2011]Problem b(莫反&整除分块)

洛谷P2522 - [HAOI2011]Problem b

P2522 [HAOI2011]Problem b