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 ...
随机推荐
- [web开发] Vue + spring boot + echart 微博爬虫展示平台
1.微博登录 2.爬取数据 3.mysql存储 4.pyechart本地展示 5.用vue搭建网站web展示 先放图: 1.微博登录 新浪微博的登录不是简单的post就能解决的,他的登录有加密,所以我 ...
- Dojo的on函数(以前的dojo.connect)
同jQuery的on函数: require(["esri/map", "dojo/on"], function(Map, on) { // ... on(my ...
- mysql中添加数据时,报错(incorrect string value:'\xf0\x9f ) 字符转换不正确
这个问题,原因是UTF-8编码有可能是两个.三个.四个字节.Emoji表情或者某些特殊字符是4个字节,而Mysql的utf8编码最多3个字节,所以数据插不进去. 在网上搜了一下解决问题的方案,我选了一 ...
- sqlserver的实例名忘记了
电脑图标右击/管理/服务和应用程序/服务 也可以直接services.msc打开 打开服务,找到sqlserver的服务,这个服务括号中的名称就是实例名了,但是要加上localhost,也就是loca ...
- 修改broadcom 4322无线网卡ID教程,不再显示第三方无线网卡
本帖最后由 hellokingabc 于 2016-1-11 03:07 编辑 黑苹果已经基本完美,但是无线网卡总是出现问题,经常断网,经过搜索,原因在于无线网卡在OSX系统下显示为第三方无线网卡,只 ...
- VueX源码分析(2)
VueX源码分析(2) 剩余内容 /module /plugins helpers.js store.js helpers要从底部开始分析比较好.也即先从辅助函数开始再分析那4个map函数mapSta ...
- 基础的Mapgis三维二次开发-插件式
最近在做一个杭州石油的项目开发一个小系统. 1.命令必须是 ICommand 的派生类 using System; using System.Collections.Generic; using Sy ...
- Create & use FTP service on Ubuntu(在Ubuntu上搭建并使用FTP服务)
Check if the FTP service has been installed.(检查是否已安装) Vsftpd --version If it has not install,Pres ...
- 使用powershell批量更新git仓库
Get-ChildItem D:\GitHub\NetCore | ForEach-Object -Process{ cd $_.name; git pull; cd ../ }
- Python学习笔记:open函数和with临时运行环境(文件操作)
open函数 1.open函数: file=open(filename, encoding='utf-8'),open()函数是Python内置的用于对文件的读写操作,返回的是文件的流对象(而不是文件 ...