CodeForces839D[莫比乌斯反演] Codeforces Round #428 (Div. 2)
/*CodeForces839D[莫比乌斯反演]*/
#include <bits/stdc++.h>
typedef long long LL;
const LL MOD = 1000000007LL;
using namespace std;
int n, maxa = , mina = 0x3f3f3f3f;
LL m[], F[], f[];
int sum[], a[];
int prime[], vis[], mu[];
void mo_init(int N) {
memset(vis, , sizeof(vis));
mu[] = ;
int cnt = ;
for (int i = ; i < N; i++)
{
if (!vis[i])
{
prime[cnt++] = i;
mu[i] = -;
}
for (int j = ; j < cnt && i * prime[j] < N; j++)
{
vis[i * prime[j]] = ;
if (i % prime[j]) mu[i * prime[j]] = -mu[i];
else
{
mu[i * prime[j]] = ;
break;
}
}
}
}
void solve() {
for (int i = ; i < n; i++) {
for (int j = ; j * j <= a[i]; j++) {
if (a[i] % j == ) {
if (j * j == a[i]) {
sum[j]++;
}
else {
sum[j]++, sum[a[i] / j]++;
}
}
}
}
LL ans = ;
for (int i = ; i <= maxa; i++) {
F[i] = sum[i] * m[sum[i] - ] % MOD;
}
for (int i = ; i <= maxa; i++) {
for (int j = i; j <= maxa; j += i) {
f[i] = (f[i] + mu[j / i] * F[j] % MOD) % MOD;
}
ans = (ans + f[i] * i % MOD) % MOD;
}
printf("%lld\n", ans);
}
void init() {
mo_init();
m[] = 1LL;
for (int i = ; i <= n; i++) {
m[i] = m[i - ] * 2LL % MOD;
}
}
int main() {
scanf("%d", &n);
for (int i = ; i < n; i++) {
scanf("%d", &a[i]);
maxa = max(maxa, a[i]);
mina = min(mina, a[i]);
} init(), solve();
return ;
}
CodeForces839D[莫比乌斯反演] Codeforces Round #428 (Div. 2)的更多相关文章
- CodeForces 839D - Winter is here | Codeforces Round #428 (Div. 2)
赛后听 Forever97 讲的思路,强的一匹- - /* CodeForces 839D - Winter is here [ 数论,容斥 ] | Codeforces Round #428 (Di ...
- CodeForces 839C - Journey | Codeforces Round #428 (Div. 2)
起初误以为到每个叶子的概率一样于是.... /* CodeForces 839C - Journey [ DFS,期望 ] | Codeforces Round #428 (Div. 2) */ #i ...
- CodeForces 839B - Game of the Rows | Codeforces Round #428 (Div. 2)
血崩- - /* CodeForces 839B - Game of the Rows [ 贪心,分类讨论] | Codeforces Round #428 (Div. 2) 注意 2 7 2 2 2 ...
- Codeforces Round #428 (Div. 2) 题解
题目链接:http://codeforces.com/contest/839 A. Arya and Bran 题意:每天给你一点糖果,如果大于8个,就只能给8个,剩下的可以存起来,小于8个就可以全部 ...
- Codeforces Round #428 (Div. 2) D. Winter is here 容斥
D. Winter is here 题目连接: http://codeforces.com/contest/839/problem/D Description Winter is here at th ...
- Codeforces Round #428 (Div. 2)E. Mother of Dragons
http://codeforces.com/contest/839/problem/E 最大团裸题= =,用Bron–Kerbosch算法,复杂度大多博客上没有,维基上查了查大约是O(3n/3) 最大 ...
- 【Codeforces Round #428 (Div. 2) B】Game of the Rows
[Link]:http://codeforces.com/contest/839/problem/B [Description] 给你n排的如题目所示的位置; 同一排中(1,2) 算相邻; (3,4) ...
- 【Codeforces Round #428 (Div. 2) C】Journey
[Link]:http://codeforces.com/contest/839/problem/C [Description] 给一棵树,每当你到一个点x的时候,你进入x的另外一每一个出度的概率都是 ...
- Codeforces Round #428 (Div. 2)A,B,C
A. Arya and Bran time limit per test 1 second memory limit per test 256 megabytes input standard inp ...
随机推荐
- 洛谷 P2002 消息扩散
题目背景 本场比赛第一题,给个简单的吧,这 100 分先拿着. 题目描述 有n个城市,中间有单向道路连接,消息会沿着道路扩散,现在给出n个城市及其之间的道路,问至少需要在几个城市发布消息才能让这所有n ...
- C基础的练习集及测试答案(1-15)
练习题:注:标有(课堂)字样的为课上练习,其他为课下练习基础题(50题)1.(课堂)编写程序,输出“XXX欢迎来到动物园!”(XXX是自己的名字). //1.(课堂)编写程序,输出“XXX欢迎来到动物 ...
- HDU 4738 Caocao's Bridges taijan (求割边,神坑)
神坑题.这题的坑点有1.判断连通,2.有重边,3.至少要有一个人背*** 因为有重边,tarjan的时候不能用子结点和父节点来判断是不是树边的二次访问,所以我的采用用前向星存边编号的奇偶性关系,用^1 ...
- flask 快速入门链接
http://docs.jinkan.org/docs/flask/quickstart.html
- Hybrid App开发之Html基本标签使用
前言: 前面简单学习了html简单标签的使用,今天学习一下其他的标签的使用. HTML的超链接 1.)创建一个超链接 <div> <p> <a href="ht ...
- 使用EventLog组件读写事件日志
实现效果: 知识运用: Eventlog类的SourceExists方法 //确定指定的事件源是否已在本地计算机注册 public static bool SourceExists(string s ...
- Linux学习日记:第二天
今天学习vi编辑命令: root@ubuntu:vi hello.java 使用到的命令: 插入命令: a 和 i:在当前光标前或后插入文本(A 和 I 分别在当前行行末或行首插入文本): o 和 ...
- STL之stack操作
c++ stl栈stack介绍 C++ Stack(堆栈) 是一个容器类的改编,为程序员提供了堆栈的全部功能,——也就是说实现了一个先进后出(FILO)的数据结构. c++ stl栈stack的头文件 ...
- 【线段树 扫描线 二维数点】loj#6276. 果树
路径计数转成二维数点很妙啊 题目描述 NiroBC 姐姐是个活泼的少女,她十分喜欢爬树,而她家门口正好有一棵果树,正好满足了她爬树的需求. 这颗果树有 $N$ 个节点,标号 $1 \ldots N$ ...
- Unity基础-外部导入C# Dll(汇编集)
外部导入C# Dll(汇编集) 使用创建一个dll工程 添加依赖的dll 导入Unity中,放入Assets的任意文件夹中 使用代码生成的dll汇编集只要"use dll的名字"引 ...