题意:

给n个正整数,求有多少个GCD为1的子序列。答案对1e9+7取模。

1<=n<=1e5,数字ai满足1<=ai<=1e5

分析:

设f(x)表示以x为公约数的子序列个数

那么ans=f(1)- Σf(pi) + Σf(pi*pj) - Σf(pi*pj*pk) ........

注意到对于一个f(x),它对结果的贡献是:

  若x为合数,那么前面系数为0

  若x由奇数个素数组成,那么系数是-1

  若x由偶数个素数组成,那么系数是1

这明显就是莫比乌斯函数……直接一个线性筛出来

那么问题就是f(x)怎么求,这显然就是f(x)=2^num(x) - 1 (num(x)表示原先序列里有多少个数是x的倍数)

Codeforces 803F(容斥原理)的更多相关文章

  1. 【codeforces 803F】Coprime Subsequences

    [题目链接]:http://codeforces.com/contest/803/problem/F [题意] 给你一个序列; 问你这个序列里面有多少个子列; 且这个子列里面的所有数字互质; [题解] ...

  2. Codeforces 803F Coprime Subsequences (容斥)

    Link:http://codeforces.com/contest/803/problem/F 题意:给n个数字,求有多少个GCD为1的子序列. 题解:容斥!比赛时能写出来真是炒鸡开森啊! num[ ...

  3. Codeforces 803F - Coprime Subsequences(数论)

    原题链接:http://codeforces.com/contest/803/problem/F 题意:若gcd(a1, a2, a3,...,an)=1则认为这n个数是互质的.求集合a中,元素互质的 ...

  4. CodeForces - 803F

    http://codeforces.com/problemset/problem/803/F #include <iostream> #include <cstdio> #in ...

  5. CodeForces 803F Coprime Subsequences

    $dp$. 记$dp[i]$表示$gcd$为$i$的倍数的子序列的方案数.然后倒着推一遍减去倍数的方案数就可以得到想要的答案了. #include <iostream> #include ...

  6. CodeForces - 803F: Coprime Subsequences(莫比乌斯&容斥)

    Let's call a non-empty sequence of positive integers a1, a2... ak coprime if the greatest common div ...

  7. hdu4135-Co-prime & Codeforces 547C Mike and Foam (容斥原理)

    hdu4135 求[L,R]范围内与N互质的数的个数. 分别求[1,L]和[1,R]和n互质的个数,求差. 利用容斥原理求解. 二进制枚举每一种质数的组合,奇加偶减. #include <bit ...

  8. Codeforces 451E Devu and Flowers(容斥原理)

    题目链接:Codeforces 451E Devu and Flowers 题目大意:有n个花坛.要选s支花,每一个花坛有f[i]支花.同一个花坛的花颜色同样,不同花坛的花颜色不同,问说能够有多少种组 ...

  9. Codeforces Round #345 (Div. 2)【A.模拟,B,暴力,C,STL,容斥原理】

    A. Joysticks time limit per test:1 second memory limit per test:256 megabytes input:standard input o ...

随机推荐

  1. 特性property

    #property装饰器用于将被装饰的方法伪装成一个数据属性,在使用时可以不用加括号而直接引用# class People:# def __init__(self,name,weight,height ...

  2. EL表达式、JSTL

    EL表达式 一.简介 > JSP表达式 <%= %> 用于向页面中输出一个对象.        > 到JSP2.0时,在我们的页面中不允许出现 JSP表达式和 脚本片段.   ...

  3. Android 计算view 的高度

    上午在做一个QuickAction里嵌套一个ListView,在Demo运行没事,结果引入到我的项目里,发现我先让它在Button上面,结果是无视那个Button的高度,这很明显,就是那个Button ...

  4. txt通过 vb编程导入 excel

    Private Sub CommandButton1_Click() '按钮触发, '按钮触发,目前支持ASNI文本的数据, 单行 fileToOpen = Application.GetOpenFi ...

  5. 网络测速命令--speedtest

    网络测速 speedtest-cli 顾名思义,这个命令为网络测速命令,基于Python编写,测试系统网络的上传下载速度,GitHub托管的项目地址,以下列出常见的用法 安装命令 pip instal ...

  6. chomp成功的返回值是1,chomp对参数去回车符后会改变参数的值,是传入又是传出参数。$arrow_notation = ( chomp( $unpackeing = <STDIN>) );

    44 my $unpackeing;     45 my $arrow_notation = '';     46 print "Enter  name to query, enter ex ...

  7. filezilla server FTP 安装报错 "could not load TLS network. Aborting start of administration interface"

    filezilla server FTP 安装报错   "could not load TLS network. Aborting start of administration inter ...

  8. JZOJ5776. 【NOIP2008模拟】小x游世界树

    题目:[NOIP2008模拟]小x游世界树: 题目的附加题解给的很清楚,这里只给一个代码: #include<iostream> #include<cstdio> #inclu ...

  9. java枚举中常见的7中用法

    2016年08月11日 11:14:45 李学凯  原文链接https://blog.csdn.net/qq_27093465/article/details/52180865 JDK1.5引入了新的 ...

  10. LeetCode(38) Count and Say

    题目 The count-and-say sequence is the sequence of integers beginning as follows: 1, 11, 21, 1211, 111 ...