Codeforces 839 D. Winter is here (莫比乌斯反演)
来源:互联网 发布:百度云总显示网络异常 编辑:程序博客网 时间:2024/06/05 11:44
Description
Winter is here at the North and the White Walkers are close. John Snow has an army consisting of n soldiers. While the rest of the world is fighting for the Iron Throne, he is going to get ready for the attack of the White Walkers.
He has created a method to know how strong his army is. Let the i-th soldier’s strength be ai. For some k he calls i1, i2, …, ik a clan if i1 < i2 < i3 < … < ik and gcd(ai1, ai2, …, aik) > 1 . He calls the strength of that clan k·gcd(ai1, ai2, …, aik). Then he defines the strength of his army by the sum of strengths of all possible clans.
Your task is to find the strength of his army. As the number may be very large, you have to print it modulo 1000000007 (10^9 + 7).
Greatest common divisor (gcd) of a sequence of integers is the maximum possible integer so that each element of the sequence is divisible by it.
Input
The first line contains integer n (1 ≤ n ≤ 200000) — the size of the army.
The second line contains n integers a1, a2, …, an (1 ≤ ai ≤ 1000000) — denoting the strengths of his soldiers.
Output
Print one integer — the strength of John Snow’s army modulo 1000000007 (10^9 + 7).
Example input
42 3 4 6
Example output
39
题意
给出一个序列,求其中所有
思路
题意转化为公式即
等价于
我们设
设
反演以后得到
考虑枚举每一个
最终结果
AC 代码
#include<bits/stdc++.h>using namespace std;typedef long long LL;const int mod = 1e9+7;const int maxn = 1e6+10;LL sk[maxn],b[maxn],z[maxn];void solve(){ LL ans=0; for (int i=2; i<=maxn; i++) { LL v=0; for (int j=i; j<=maxn; j+=i) v+=sk[j]; if (!v) continue; ans += (v * z[i]) % mod * b[v-1] % mod; } cout << (ans+mod)%mod << endl;}void init(){ b[0]=1; for (int i=1; i<=maxn; i++) b[i]=b[i-1]*2%mod,z[i]=i; for (int i=2; i<=maxn; i++) for (int j=i+i; j<=maxn; j+=i) z[j]-= z[i];}int main(){ init(); ios::sync_with_stdio(false); int n; while(cin>>n) { memset(sk,0,sizeof(sk)); for (int i=1,x; i<=n; i++) { cin>>x; sk[x]++; } solve(); } return 0;}
- Codeforces 839 D. Winter is here (莫比乌斯反演)
- 【Codeforces 839D. Winter is here】& 莫比乌斯反演
- codeforces839D Winter is here 数论,莫比乌斯反演
- codeforces 839 D Winter is here
- Codeforces 839D Winter is here
- codeforces 839d Winter is here
- Codeforces 839D-Winter is here
- Codeforces-839D Winter is here(容斥原理)
- CodeForces 839D Winter is here (容斥原理)
- CodeForces 839D Winter is here(数学 容斥)
- Codeforces 839D Winter is here【容斥原理+数学公式】
- Codeforces 839 D. Winter is here 容斥
- Winter is here codeforces 839d 容斥
- Codeforces-822D Winter is here(DP)
- Codeforces Round #428 (Div. 2) D. Winter is here
- Codeforces 839D Winter is here 组合数公式/容斥
- CodeForces Round 428 div2 839D Winter is here(数学)(详解)
- [容斥] Codeforces#428 (Div. 2) 839D. Winter is here
- Leetcode-19: Remove Nth Node From End of List
- 在Windows上安装Elasticsearch v5.4.2
- 子进程创建do_fork
- java 中 哪些异常必须声明并捕获,否则产生编译错误
- 欢迎使用CSDN-markdown编辑器
- Codeforces 839 D. Winter is here (莫比乌斯反演)
- request.getParameterMap
- java中Map,List与Set的区别
- 使用Struts2开发程序的基本步骤
- 单体架构,SOA,微服务
- 数据的交换输出
- CVE-2012-1876浅析-Internet Explorer堆溢出漏洞
- 【ssh系列二】——SpringMVC中的注解及运用
- Chrome书签