#428 Div2 D

题意

给出一些数,现在要求找出一些数满足 \(i_1 < i_2 < i_3 < ... < i_k\) 以及 \(gcd(a_{i_1}, a_{i_2}, ..., a_{i_k}) > 1\) ,记这些数的贡献为 \(k * gcd(a_{i_1}, a_{i_2}, ..., a_{i_k}) \) 。

求每种方案的贡献之和。

分析

不得不说和 hdu6053 很类似,其实还要简单不少。

考虑枚举 \(gcd\) ,我们可以找到因子有 \(gcd\) 这个数的数有多少个,假设有因子 \(2\) 的数有 \(x\) 个,那么这些数的贡献就是 \(2 * (1*C_{x}^{1}+2*C_{x}^{2}+..+x*C_{x}^{x})\) (通过打表可以发现规律),但是在枚举因子 \(2\) 的时候可能会把 \(2\) 的倍数作为因子形成的方案也考虑了,通过容斥去处理得到最后结果。

这里容斥类似于筛法的思想,实现和理解都更简单。

code

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAXN = 2e5 + 10;
const int N = 1e6 + 10;
const int MOD = 1e9 + 7;
ll num[MAXN];
int a[N];
ll has[N];
int main() {
ll e = 1;
for(int i = 1; i < MAXN; i++) {
num[i] = (num[i - 1] * 2 + e) % MOD;
e = e * 2 % MOD;
}
int n;
scanf("%d", &n);
for(int i = 0; i < n; i++) {
int x;
scanf("%d", &x);
a[x]++;
}
ll ans = 0;
for(int i = N - 1; i >= 2; i--) {
int s = 0;
for(int j = i; j < N; j += i) {
s += a[j];
}
has[i] = num[s];
for(int j = 2 * i; j < N; j += i) {
has[i] = (has[i] - has[j] + MOD) % MOD;
}
ans = (ans + 1LL * i * has[i]) % MOD;
}
printf("%I64d\n", ans);
return 0;
}

Codeforces #428 Div2 D的更多相关文章

  1. Codeforces #180 div2 C Parity Game

    // Codeforces #180 div2 C Parity Game // // 这个问题的意思被摄物体没有解释 // // 这个主题是如此的狠一点(对我来说,),不多说了这 // // 解决问 ...

  2. Codeforces #541 (Div2) - E. String Multiplication(动态规划)

    Problem   Codeforces #541 (Div2) - E. String Multiplication Time Limit: 2000 mSec Problem Descriptio ...

  3. Codeforces #541 (Div2) - F. Asya And Kittens(并查集+链表)

    Problem   Codeforces #541 (Div2) - F. Asya And Kittens Time Limit: 2000 mSec Problem Description Inp ...

  4. Codeforces #541 (Div2) - D. Gourmet choice(拓扑排序+并查集)

    Problem   Codeforces #541 (Div2) - D. Gourmet choice Time Limit: 2000 mSec Problem Description Input ...

  5. Codeforces #548 (Div2) - D.Steps to One(概率dp+数论)

    Problem   Codeforces #548 (Div2) - D.Steps to One Time Limit: 2000 mSec Problem Description Input Th ...

  6. 【Codeforces #312 div2 A】Lala Land and Apple Trees

    # [Codeforces #312 div2 A]Lala Land and Apple Trees 首先,此题的大意是在一条坐标轴上,有\(n\)个点,每个点的权值为\(a_{i}\),第一次从原 ...

  7. codeforces round #428 div2

    A:暴力模拟,能加就加,如果累计到了8就加上,每次累积 #include<bits/stdc++.h> using namespace std; int main() { ; scanf( ...

  8. Codeforces #263 div2 解题报告

    比赛链接:http://codeforces.com/contest/462 这次比赛的时候,刚刚注冊的时候非常想好好的做一下,可是网上喝了个小酒之后.也就迷迷糊糊地看了题目,做了几题.一觉醒来发现r ...

  9. codeforces #round363 div2.C-Vacations (DP)

    题目链接:http://codeforces.com/contest/699/problem/C dp[i][j]表示第i天做事情j所得到最小的假期,j=0,1,2. #include<bits ...

随机推荐

  1. 获取本地ip地址 C#

    与ipconfig获取的所有信息一致的方法: private void GetIp() { System.Diagnostics.Process cmdp= new System.Diagnostic ...

  2. Java的Properties使用及格式定义

    java.util.Properties extends Hashtable<Object,Object> 方便读取 键值对 格式的文本资源工具 常用方法一览 初始化对象 new Prop ...

  3. MySQL DELAY_KEY_WRITE Option

    delay_key_write   This option applies only to MyISAM tables. It can have one of the following values ...

  4. recycleview的基础Adapter

    .封装了一个基础的adapter.,用于recycleview的快捷使用有BaseAdapter,BaseViewHolder,PAdapter,MainActivity public abstrac ...

  5. 关于跨域策略文件crossdomain.xml文件--配置实例

    转载自:http://bbs.phpchina.com/blog-52440-191623.html 我一直不太明白crossdomain.xml文件是干嘛用的,今天总算比较清楚的知道了一下. 这是F ...

  6. 问题总结——window平台下grunt\bower安装后无法运行的问题

    一.问题: 安装grunt或者bower后,在cmd控制台运行grunt -version 或者 bower -v会出现:“xxx不是内部或外部命令,也不是可运行的程序或批处理文件”,

  7. 【数据结构】bzoj2957楼房重建

    Description 小A的楼房外有一大片施工工地,工地上有N栋待建的楼房.每天,这片工地上的房子拆了又建.建了又拆.他经常无聊地看着窗外发呆,数自己能够看到多少栋房子. 为了简化问题,我们考虑这些 ...

  8. CF 200 div.1 A

    2013-10-11 16:45 Rational Resistance time limit per test 1 second memory limit per test 256 megabyte ...

  9. linux基础之nginx和nfs服务

      第一部分: 一.nginx服务安装nginx包(源码安装)1.先cd /etc/yum.repos.d目录下2.yum install epel-release -y(安装扩展包)3.yum in ...

  10. kuangbin 带你飞 概率期望

    正推不行就逆推! 经典问题:生日悖论 换成其互斥事件:m个人, 每个人生日都不相同的概率 ≤ 0.5 时最小人数. 这就是邮票收集问题的变形:每个邮票至少出现一次的概率 小于等于 0.5 邮票收集问题 ...