当前位置:网站首页>CF803F(容斥原理+莫比乌斯函数)
CF803F(容斥原理+莫比乌斯函数)
2022-08-08 17:41:00 【野指针*】
题意要求gcd=1的子序列个数.
我们想到求gcd!=1的子序列个数,看到值域很小,我们考虑对值域下手,因为是gcd=1,我们联想到互质,于是我们可以使用容斥求个数,详细来说就是,含有1的因子的个数-含有2,3,5,7,11....一个质因子的个数+含有2*3,3*5....两个质因子的个数-......由于普通的容斥原理是2^n的,因为选的是质因数,所以我们用莫比乌斯函数实现.
#include <bits/stdc++.h>
#define int long long
#define IOS ios::sync_with_stdio(false), cin.tie(0)
#define ll long long
// #define double long double
#define ull unsigned long long
#define PII pair<int, int>
#define PDI pair<double, int>
#define PDD pair<double, double>
#define debug(a) cout << #a << " = " << a << endl
#define point(n) cout << fixed << setprecision(n)
#define all(x) (x).begin(), (x).end()
#define mem(x, y) memset((x), (y), sizeof(x))
#define lbt(x) (x & (-x))
#define SZ(x) ((x).size())
#define inf 0x3f3f3f3f
#define INF 0x3f3f3f3f3f3f3f3f
namespace nqio{const unsigned R = 4e5, W = 4e5; char *a, *b, i[R], o[W], *c = o, *d = o + W, h[40], *p = h, y; bool s; struct q{void r(char &x){x = a == b && (b = (a = i) + fread(i, 1, R, stdin), a == b) ? -1 : *a++;} void f(){fwrite(o, 1, c - o, stdout); c = o;} ~q(){f();}void w(char x){*c = x;if (++c == d) f();} q &operator >>(char &x){do r(x);while (x <= 32); return *this;} q &operator >>(char *x){do r(*x); while (*x <= 32); while (*x > 32) r(*++x); *x = 0; return *this;} template<typename t> q&operator>>(t &x){for (r(y),s = 0; !isdigit(y); r(y)) s |= y == 45;if (s) for (x = 0; isdigit(y); r(y)) x = x * 10 - (y ^ 48); else for (x = 0; isdigit(y); r(y)) x = x * 10 + (y ^ 48); return *this;} q &operator <<(char x){w(x);return *this;}q &operator<< (char *x){while (*x) w(*x++); return *this;}q &operator <<(const char *x){while (*x) w(*x++); return *this;}template<typename t> q &operator<< (t x) {if (!x) w(48); else if (x < 0) for (w(45); x; x /= 10) *p++ = 48 | -(x % 10); else for (; x; x /= 10) *p++ = 48 | x % 10; while (p != h) w(*--p);return *this;}}qio; }using nqio::qio;
using namespace std;
const int N = 1e6 + 10, MOD = 1e9 + 7;
int n, a[N], cc[N];
int mu[N], vis[N], primes[N], sum[N], cnt;
void get_mu(int n)
{
cnt = 0, mu[1] = 1;
for(int i = 2; i <= n; ++ i) {
if(vis[i] == 0){
primes[ ++ cnt] = i;
mu[i] = -1;
}
for(int j = 1; j <= cnt && i * primes[j] <= n; ++ j) {
vis[primes[j] * i] = 1;
if(i % primes[j] == 0) break;
mu[i * primes[j]] -= mu[i];
//mi[i * primes[j]] = -mu[i];
}
}
for(int i = 1; i <= n; ++ i)
sum[i] += sum[i - 1] + mu[i];
}
int qmi(int a, int k, int p) {
int res = 1;
while (k) {
if (k & 1) res = res * a % p;
k >>= 1;
a = a * a % p;
}
return res;
}
void solve() {
qio >> n;
get_mu(1e6);
int mx = 0;
for (int i = 1, x; i <= n; ++i) qio >> x, ++cc[x], mx = max(mx, x);
int ans = 0;
for (int i = 1; i <= mx; ++i) {
int s = 0;
for (int j = 1; j <= mx / i; ++j) s += cc[i * j];
ans = ((ans + mu[i] * (qmi(2, s, MOD) - 1) % MOD) % MOD + MOD) % MOD;
}
qio << ans << "\n";
}
signed main() {
// IOS;
int T = 1;
// qio >> T;
while (T--) solve();
}
边栏推荐
猜你喜欢
Reprinted, the fragment speaks very well, the big guy
一甲子,正青春,CCF创建六十周年庆典在苏州举行
canvas城市灯火夜景动画js特效
【CC3200AI 实验教程4】疯壳·AI语音人脸识别(会议记录仪/人脸打卡机)-GPIO
List<String>用空串替换null值,并且都加上单引号,并且转为字符串用,分割
DSPE-PEG-Biotin,385437-57-0,磷脂-聚乙二醇-生物素用于生物分子的检测和纯化
测试/开发程序员停滞不前,倦怠怎么办?突破各种失败和挫折......
CF533B(树形dp+转移技巧)
CF633C(trie树dfs / 字符串hash + 线性dp)
Cy5反式环辛烯,TCO-Cy5,Cy5 trans-cyclooctene标记生物分子
随机推荐
The difference between rv and sv
【AI玩家养成记 • 第3期】AI开发者必备!史上最适合新手的昇腾AI环境搭建教程!!
咸阳广发证券股票开户安全吗,需要准备什么证件
js切换新闻列表样式
CF633C(trie树dfs / 字符串hash + 线性dp)
新版松鼠as换源操作
从2022投影行业最新报告,读懂2022年家用智能投影仪该怎么选!
串行通信:常见的串行通信接口协议UART、SPI、I2C简介
【云图说】第252期 初识云速建站服务
openGauss社区七月运作报告
Cholesterol-PEG-DBCO,CLS-PEG-DBCO,胆固醇-聚乙二醇-二苯基环辛炔一种环炔烃
盘点检索任务中的损失函数
L2-011 玩转二叉树 (25 分) (二叉树)
2.5W 字详解线程与锁了,面试随便问!!
poj1961 Period(KMP)
为什么MySQL的主键查询这么快
2 prerequisites for the success of "digital transformation" of enterprises!
arm交叉编译
无需精子卵子子宫体外培育胚胎,Cell论文作者这番话让网友们炸了
Tensorflow教程(二)——基本概念与搭建流程