原题链接:http://codeforces.com/contest/803/problem/F 题意:若gcd(a1, a2, a3,...,an)=1则认为这n个数是互质的.求集合a中,元素互质的集合的个数. 思路:首先知道一个大小为n的集合有2n-1个非空子集,运用容斥,对某个数,我们可以求出它作为因子出现的个数(假设为ki).推一下式子,可以得到结果就等于:Σmiu[i]*(2i-1),其中miu[i]是莫比乌斯函数. 时间复杂度为:O(n*sqrt(max_a)),看起来似乎会超时,实…
Link:http://codeforces.com/contest/803/problem/F 题意:给n个数字,求有多少个GCD为1的子序列. 题解:容斥!比赛时能写出来真是炒鸡开森啊! num[i]: 有多少个数字是 i 的倍数. 所有元素都是1的倍数的序列有:$2^n-1$个.先把$2^n-1$设为答案 所有元素都是质数的倍数的序列有:$\sum 2^{num[p_1]} - 1$个,这些序列不存在的,得从答案中减去. 所有元素都是两质数之积的倍数的序列有:$\sum 2^{num[p_…
$dp$. 记$dp[i]$表示$gcd$为$i$的倍数的子序列的方案数.然后倒着推一遍减去倍数的方案数就可以得到想要的答案了. #include <iostream> #include <cstdio> #include <cstring> #include <string> #include <cmath> #include <queue> #include <stack> #include <vector>…
Let's call a non-empty sequence of positive integers a1, a2... ak coprime if the greatest common divisor of all elements of this sequence is equal to 1. Given an array a consisting of n positive integers, find the number of its coprime subsequences.…
题目链接: F. Coprime Subsequences time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Let's call a non-empty sequence of positive integers a1, a2... ak coprime if the greatest common divisor of al…
[CodeForces - 1225C]p-binary [数论][二进制] 标签: 题解 codeforces题解 数论 题目描述 Time limit 2000 ms Memory limit 524288 kB Source Technocup 2020 - Elimination Round 2 Tags bitmasks brute force math *1600 Site https://codeforces.com/problemset/problem/1225/c 题面 Exa…
[题目链接]:http://codeforces.com/contest/803/problem/F [题意] 给你一个序列; 问你这个序列里面有多少个子列; 且这个子列里面的所有数字互质; [题解] 计算cnt[x]; 表示数组里有多少个数是x的倍数; 则某个子列里面所有的数字都能被x整除的子列个数为2cnt[x]−1 把这个值记为f[x]; 则我们用需要用容斥原理; 把所有能被2,3,..n整除的子列删除掉; 这里面会有重复计数的问题; 解决方式是,从大到小枚举f[x] 然后对于y=i*x的…
A. Co-prime Array time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output You are given an array of n elements, you must make it a co-prime array in as few moves as possible. In each move you can i…
题目链接: C. Subsequences time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output For the given sequence with n different elements find the number of increasing subsequences with k + 1 elements. It is…
CO-PRIME 时间限制:1000 ms  |  内存限制:65535 KB 难度:3 描写叙述 This problem is so easy! Can you solve it? You are given a sequence which contains n integers a1,a2--an, your task is to find how many pair(ai, aj)(i < j) that ai and aj is co-prime. 输入 There are mult…