BZOJ2693jzptab

简单般Bzoj2154: Crash的数字表格

Sol

增加了数据组数T<=10000
推到
ans=Nd=1dNdi=1μ(i)i2(Ndi+1)Ndi2(Mdi+1)Mdi2
S(i)=(i+1)i2dik
=Nk=1S(Nk)S(Mk)ki|kiμ(i)
f(n)=i|niμ(i)线

# include 
# define RG register
# define IL inline
# define Fill(a, b) memset(a, b, sizeof(a))
using namespace std;
typedef long long ll;
const int _(1e7 + 1), MOD(1e8 + 9);

IL ll Read(){
    char c = '%'; ll x = 0, z = 1;
    for(; c > '9' || c < '0'; c = getchar()) if(c == '-') z = -1;
    for(; c >= '0' && c <= '9'; c = getchar()) x = x * 10 + c - '0';
    return x * z;
}

int prime[_], f[_], num, s[_];
bool isprime[_];

IL void Prepare(){
    isprime[1] = 1; s[1] = f[1] = 1;
    for(RG int i = 2; i < _; ++i){
        if(!isprime[i]) prime[++num] = i, f[i] = 1 - i;
        for(RG int j = 1; j <= num && i * prime[j] < _; ++j){
            isprime[i * prime[j]] = 1;
            if(i % prime[j])  f[i * prime[j]] = 1LL * f[i] * f[prime[j]] % MOD;
            else{  f[i * prime[j]] = f[i]; break;    }
        }
        s[i] = (s[i - 1] + 1LL * i * f[i] % MOD) % MOD;
    }
}

IL ll S(RG ll x){  return x * (x + 1) / 2 % MOD;  }

int main(RG int argc, RG char *argv[]){
    Prepare();
    for(RG ll T = Read(), n, m; T; --T){
        RG ll ans = 0; n = Read(); m = Read();
        if(n > m) swap(n, m);
        for(RG ll i = 1, j; i <= n; i = j + 1){
            j = min(n / (n / i), m / (m / i));
            (ans += 1LL * (s[j] - s[i - 1] + MOD) % MOD * S(n / i) % MOD * S(m / i) % MOD) %= MOD;
        }
        printf("%lld\n", (ans + MOD) % MOD);
    }
    return 0;
}

你可能感兴趣的:(反演与容斥)