中文题意
给你个数
,问你从中挑选非空的子序列并且保证子序列
的子序列数量有多少个。
。
Solution
正向不太好做,那么就反向思考,我们可以选择的总的子序列个数是个。减去选择一个素数
这些子序列个数,再加上选择两个不同素数乘积
这些的子序列数量,再减去选择三个素数的,依次容斥就是答案了。注意我们还需要跳过例如
这样的子序列,因为我们只能选择
个不同的素数相乘计算贡献。那么对于每次选择的
的贡献,也就是有几个统计
中有几个可以被
整除,求一下这些数的子序列贡献即可。
#include <bits/stdc++.h>
using namespace std;
#define js ios::sync_with_stdio(false);cin.tie(0); cout.tie(0)
#define all(__vv__) (__vv__).begin(), (__vv__).end()
#define endl "\n"
#define pai pair<int, int>
#define ms(__x__,__val__) memset(__x__, __val__, sizeof(__x__))
#define rep(i, sta, en) for(int i=sta; i<=en; ++i)
#define repp(i, sta, en) for(int i=sta; i>=en; --i)
typedef long long ll; typedef unsigned long long ull; typedef long double ld;
inline ll read() { ll s = 0, w = 1; char ch = getchar(); for (; !isdigit(ch); ch = getchar()) if (ch == '-') w = -1; for (; isdigit(ch); ch = getchar()) s = (s << 1) + (s << 3) + (ch ^ 48); return s * w; }
inline void print(ll x, int op = 10) { if (!x) { putchar('0'); if (op) putchar(op); return; } char F[40]; ll tmp = x > 0 ? x : -x; if (x < 0)putchar('-'); int cnt = 0; while (tmp > 0) { F[cnt++] = tmp % 10 + '0'; tmp /= 10; } while (cnt > 0)putchar(F[--cnt]); if (op) putchar(op); }
inline ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
ll qpow(ll a, ll b) { ll ans = 1; while (b) { if (b & 1) ans *= a; b >>= 1; a *= a; } return ans; } ll qpow(ll a, ll b, ll mod) { ll ans = 1; while (b) { if (b & 1)(ans *= a) %= mod; b >>= 1; (a *= a) %= mod; }return ans % mod; }
const int dir[][2] = { {0,1},{1,0},{0,-1},{-1,0},{1,1},{1,-1},{-1,1},{-1,-1} };
const int MOD = 1e9 + 7;
const int INF = 0x3f3f3f3f;
struct Node {
ll val;
int id;
bool operator < (const Node& opt) const {
return val < opt.val;
}
};
const int N = 1e5 + 7;
ll n, m;
ll p[N];
int vis[N], cnt[N];
int a[N];
void solve() {
p[0] = 1;
rep(i, 1, N - 1) p[i] = (p[i - 1] << 1) % MOD;
rep(i, 2, N - 1) {
if (!vis[i]) {
++cnt[i];
for (int j = 2 * i; j < N; j += i) {
vis[j] = 1;
if (cnt[j] == -1) continue;
if ((j / i) % i == 0) cnt[j] = -1; // j一定是i的倍数,如果是两个相同i累乘的答案一定是不存在容斥之中的
else ++cnt[j];
}
}
}
n = read();
rep(i, 1, n) {
int x = read();
for (int j = 1; j * j <= x; ++j) {
if (x % j) continue;
++a[j];
if (j * j != x) ++a[x / j];
}
}
ll ans = p[n] - 1; // 总的序列是2^n - 1
rep(i, 2, N - 1) {
if (cnt[i] == -1) continue;
if (cnt[i] & 1)
ans -= p[a[i]] - 1;
else
ans += p[a[i]] - 1;
ans = (ans + MOD) % MOD;
}
print(ans);
}
int main() {
//int T = read(); while (T--)
solve();
return 0;
} 
京公网安备 11010502036488号