# BZOJ3930 [CQOI2015]选数【莫比乌斯反演】

2 2 2 4

3

## 思路

$g(x)$是选出gcd是x的倍数的方案数
$g(x)=\sum_{x|d}f(d)$

//Author: dream_maker
#include<bits/stdc++.h>
using namespace std;
//----------------------------------------------
//typename
typedef long long ll;
//convenient for
#define fu(a, b, c) for (int a = b; a <= c; ++a)
#define fd(a, b, c) for (int a = b; a >= c; --a)
#define fv(a, b) for (int a = 0; a < (signed)b.size(); ++a)
//inf of different typename
const int INF_of_int = 1e9;
const ll INF_of_ll = 1e18;
template <typename T>
bool w = 1;x = 0;
char c = getchar();
while (!isdigit(c) && c != '-') c = getchar();
if (c == '-') w = 0, c = getchar();
while (isdigit(c)) {
x = (x<<1) + (x<<3) + c -'0';
c = getchar();
}
if (!w) x = -x;
}
template <typename T>
void Write(T x) {
if (x < 0) {
putchar('-');
x = -x;
}
if (x > 9) Write(x / 10);
putchar(x % 10 + '0');
}
//----------------------------------------------
const int N = 1e5 + 10;
const int Mod = 1e9 + 7;
int n, k, l, r;
int mu[N], prime[N], tot = 0;
bool vis[N];
int add(int a, int b) {
a += b;
if (a >= Mod) return a - Mod;
if (a < 0) return a + Mod;
return a;
}
int mul(int a, int b) {
return 1ll * a * b % Mod;
}
int fast_pow(int a, int b) {
int res = 1;
while (b) {
if (b & 1) res = mul(res, a);
b >>= 1;
a = mul(a, a);
}
return res;
}
void init() {
mu[1] = 1;
fu(i, 2, N - 1) {
if (!vis[i]) {
mu[i] = -1;
prime[++tot] = i;
}
fu(j, 1, tot) {
if (i * prime[j] >= N) break;
vis[i * prime[j]] = 1;
if (i % prime[j]) {
mu[i * prime[j]] = -mu[i];
} else {
mu[i * prime[j]] = 0;
break;
}
}
}
}
int calc(int vl) {
int len = r / vl - (l - 1) / vl;