CodeForces 803F Coprime Subsequences
$dp$。
记$dp[i]$表示$gcd$为$i$的倍数的子序列的方案数。然后倒着推一遍减去倍数的方案数就可以得到想要的答案了。
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
using namespace std; int n;
long long b[100010];
long long a[100010];
long long mod = 1e9+7; int main()
{
scanf("%d",&n);
for(int i=1;i<=n;i++)
{
int x; scanf("%d",&x);
for(int j=1;j*j<=x;j++)
{
if(x%j!=0) continue;
a[j]++;
if(x/j!=j) a[x/j]++;
}
} b[0]=1;
for(int i=1;i<=100000;i++) b[i] = (b[i-1]*2)%mod; for(int i=1;i<=100000;i++)
{
a[i] = (b[a[i]]-1+mod)%mod;
} for(int i=100000;i>=1;i--)
{
int tmp = i;
tmp=tmp+i;
while(tmp<=100000)
{
a[i] = (a[i]- a[tmp]+mod)%mod;
tmp=tmp+i;
}
} printf("%lld\n",a[1]); return 0;
}
CodeForces 803F Coprime Subsequences的更多相关文章
- Codeforces 803F Coprime Subsequences (容斥)
Link:http://codeforces.com/contest/803/problem/F 题意:给n个数字,求有多少个GCD为1的子序列. 题解:容斥!比赛时能写出来真是炒鸡开森啊! num[ ...
- Codeforces 803F - Coprime Subsequences(数论)
原题链接:http://codeforces.com/contest/803/problem/F 题意:若gcd(a1, a2, a3,...,an)=1则认为这n个数是互质的.求集合a中,元素互质的 ...
- CodeForces - 803F: Coprime Subsequences(莫比乌斯&容斥)
Let's call a non-empty sequence of positive integers a1, a2... ak coprime if the greatest common div ...
- F. Coprime Subsequences
题目链接: F. Coprime Subsequences time limit per test 2 seconds memory limit per test 256 megabytes inpu ...
- 【codeforces 803F】Coprime Subsequences
[题目链接]:http://codeforces.com/contest/803/problem/F [题意] 给你一个序列; 问你这个序列里面有多少个子列; 且这个子列里面的所有数字互质; [题解] ...
- Codeforces 660A. Co-prime Array 最大公约数
A. Co-prime Array time limit per test 1 second memory limit per test 256 megabytes input standard in ...
- codeforces 597C C. Subsequences(dp+树状数组)
题目链接: C. Subsequences time limit per test 1 second memory limit per test 256 megabytes input standar ...
- Codeforces 1132G Greedy Subsequences [线段树]
洛谷 Codeforces 看到题解那么少就来发一篇吧-- 思路 看完题目一脸懵逼,感觉无从下手. 莫名其妙地想到笛卡尔树,但笛卡尔树好像并没有太大作用. 考虑把笛卡尔树改一下:每个点的父亲设为它的右 ...
- Codeforces 915G Coprime Arrays 莫比乌斯反演 (看题解)
Coprime Arrays 啊,我感觉我更本不会莫比乌斯啊啊啊, 感觉每次都学不会, 我好菜啊. #include<bits/stdc++.h> #define LL long long ...
随机推荐
- C++对象与其第一个非静态成员地址相同
由于对象的内存空间里是按顺序依次存储了它的非静态成员变量,因此对象和它的第一个非静态成员变量的地址是相同的: class A { private: int i; } int main() { A a; ...
- Oracle中查询当前数据库中的所有表空间和对应的数据文件语句命令
Oracle中查询当前数据库中的所有表空间和对应的数据文件语句命令 ------------------------------------------------------------------ ...
- ASP.NET MVC4+EasyUI+EntityFrameWork5权限管理系统——数据库的设计(一)
快一年没写博客了,这段时间感觉好迷茫,写点博客,记录一下自己的成长过程,希望对大家也有帮助 先上图 一个用户可以有多个角色,一个用户可以属于多个部门,这些都可以控制到权限,有时特殊要求,同样的部门和角 ...
- 优美的代码:do...while(0)
1.背景 最近再看一个开源代码的时候,看到很多宏经常这么写的: #define XXX do{\ ...\ }) 一眼看到的时候就知道这一份代码执行一次,那么do...while还有什么意义呢?在查阅 ...
- input只读属性readonly和disabled的区别
主要区别: 参考: http://bbs.html5cn.org/forum.php?mod=viewthread&tid=84113&highlight=input http://b ...
- JSON.parse()——json字符串转JS
JSON 通常用于与服务端交换数据. 在接收服务器数据时一般是字符串. 我们可以使用 JSON.parse() 方法将数据转换为 JavaScript 对象. 语法 JSON.parse(text[, ...
- python之自然语言处理入门(一)
前言 NTLK是著名的Python自然语言处理工具包,记录一下学习NTLK的总结. 安装nltk pip install nltk # 测试 import nltk 安装相关的包 import nlt ...
- 自定义ISO结构
流程: 1.OS安装 1.1 网卡配置 1.2 密码 1.3 语言 1.4 时区 1.5 分区 1.6 rpms ... 2.软件安装 2.1 BIC Server 2.2 APP Server 2. ...
- ip_rcv && ip_rcv_finish
(1) 在inet_init中注册了类型为ETH_P_IP协议的数据包的回调ip_rcv (2) 当二层数据包接收完毕,会调用netif_receive_skb根据协议进行向上层分发 (3) 类型为E ...
- Elasticsearch5.0 安装问题集锦【转】
转自 Elasticsearch5.0 安装问题集锦 - 代码&优雅着&生活 - 博客园http://www.cnblogs.com/sloveling/p/elasticsearch ...