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 ...
随机推荐
- [LeetCode] Matrix 值修改系列,例题 Surrounded Regions,Set Matrix Zeroes
引言 Matrix内部的值修改严格来讲放在一个系列里不大合适,因为对于不同的问题,所用的算法和技巧可能完全不同,权且这样归类,以后需要时再拆分吧. 例题 1 Given a 2D board cont ...
- Vue2.0中的路由配置
Vue2.0较Vue1.0,路由有了较大改变.看一下Vue2.0中的路由如何配置: 步骤一: 在main.js文件中引入相关模块以及组件及实例化vue对象配置选项路由及渲染App组件 默认设置如下: ...
- centos7 samba匿名访问设置
[global] workgroup = WORKGROUP server string = Samba Server %v netbios name = centos security = user ...
- JVM学习十二:JVM之性能监控工具
前面我们学习了很多JVM相关的理论知识,那么本节将重点讲述的是工具的使用,正所谓:工欲善其事,必先利其器.因此,本节介绍常用的性能监控工具,用于性能监控和问题排查. 一.系统性能监控 系统性能工具用于 ...
- CodeForces - 1016B
You are given two strings ss and tt, both consisting only of lowercase Latin letters. The substring ...
- CF 900B
CF 900B Time Limit:1000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u Descript ...
- HDU 1059 Dividing (dp)
题目链接 Problem Description Marsha and Bill own a collection of marbles. They want to split the collect ...
- angular 最大字数限制
js可以通过onkeyup onkeydown判断当前节点字数. angular可以通过监听的方式: $scope.input = {//初始化,避免ng-model绑定取不到值 MaxBT:'', ...
- Postgres中tuple的组装与插入
1.相关的数据类型 我们先看相关的数据类型: HeapTupleData(src/include/access/htup.h) typedef struct HeapTupleData { uint3 ...
- C# 开发(创蓝253)手机短信验证码接口
创蓝253: https://www.253.com/ #region 获取手机验证码(创蓝253) /// <summary> /// 获取手机验证码(创蓝253) /// </s ...