Winter is here at the North and the White Walkers are close. John Snow has an army consisting of n soldiers. While the rest of the world is fighting for the Iron Throne, he is going to get ready for the attack of the White Walkers. He has created a m…
[题目链接] http://codeforces.com/contest/839/problem/D [题目大意] 给出一些数,求取出一些数,当他们的GCD大于0时,将数量乘GCD累加到答案上, 求累加和. [题解] 我们枚举GCD,统计为其倍数的数字数量,先假定其能组成的集合数为贡献, 但是我们发现在统计的过程中有多余统计的部分,比如4和8是2的倍数, 然而它们的GCD等于4,所以我们对于每个集合数的贡献要减去所有其倍数的集合数的贡献, 倒着容斥即可. [代码] #include <cstdi…
赛后听 Forever97 讲的思路,强的一匹- - /* CodeForces 839D - Winter is here [ 数论,容斥 ] | Codeforces Round #428 (Div. 2) 题意: 给出数列a[N] 对每个子集,若 gcd(a[I1], a[I2], a[I3] ..., a[In]) > 1,则贡献为 n*gcd 求总贡献和 限制: N <= 2e5,a[i] <= 1e6 分析: 记录 num[i]数组为 i 的倍数的个数 则 gcd >=…
D. Winter is here time limit per test:3 seconds memory limit per test:256 megabytes input:standard input output:standard output Winter is here at the North and the White Walkers are close. John Snow has an army consisting of n soldiers. While the res…
链接:CF839D 题目大意 给定一个数组大小为\(n(1\leq n\leq 200000)\)的数组\(a\),满足\(1\leq a_i \leq 1000000\). 选择其中任意\(len\)个数字,若\(gcd>1\),则该组数字对答案贡献为\(len*gcd\),求最终答案对\(1e9+7\)取模. 题目分析 因为\(gcd\)的本质是因数分解,可以想到,如果不考虑算重,那么: 对于一个\(gcd\)的结果\(x\),若有\(num\)个数含有\(x\)这个因数,则被选择的数可形成…
hdu4135 求[L,R]范围内与N互质的数的个数. 分别求[1,L]和[1,R]和n互质的个数,求差. 利用容斥原理求解. 二进制枚举每一种质数的组合,奇加偶减. #include <bits/stdc++.h> using namespace std; typedef long long ll; ; int fac[N], cnt; void factor(int n) { cnt = ; int limit = sqrt(n); ; i <= limit; ++i) { ) fa…
Codeforces 1178D (思维+数学) 题面 给出正整数n(不一定是质数),构造一个边数为质数的无向连通图(无自环重边),且图的每个节点的度数为质数 分析 我们先构造一个环,每个点的度数都是2.但由于n不一定是质数,我们还需要再加k条边.然后对于\(i \in [1,k]\),我们加边(i,i+n/2).当\(k\leq \frac{n}{2}\)的时候,只会把一些点的度数由2变成3,否则会出现重边问题.假设新图的边数为m,那\(m \in [n,n+\frac{n}{2}]\),如果…
题目链接:http://codeforces.com/problemset/problem/627/A 题意: 告诉你s 和 x,a + b = s    a xor b = x   a, b > 0. 让你求符合条件的a b有多少对 思路: a + b = s , a ^ b = x   ==>   s - x = (a & b) * 2 #include <bits/stdc++.h> using namespace std; typedef long long LL;…
贡献了一列WA.. 数学很神奇啊 这个题的关键是怎么才能算尾0的个数 只能相乘 可以想一下所有一位数相乘 除0之外,只有2和5相乘才能得到0 当然那些本身带0的多位数 里面肯定含有多少尾0 就含有多少对2和5 这样就知道了 就是求2和5 的对数最少的 一条路 DP就不用说了 递推 注意有0的时候的计算  特殊处理一下 #include <iostream> #include<cstdio> #include<cstring> #include<algorithm&…
Maximal GCD 题目链接:http://codeforces.com/contest/803/problem/C 题目大意: 给你n,k(1<=n,k<=1e10). 要你输出k个数,满足一下条件: ①这k个数之和等于n ②每个满足①条件的数列有最大公约数q,输出q最大的数列. 思路: 我们只需要找出这个最大的q是什么.q满足: ①q是n的 公约数 ②n/q>=(1+2+3+···+k) ③q是满足①②中的最大的 只需要通过for(long long i=1;i<sqrt(…