题意:全然平方数是指含有平方数因子的数.求第ki个非全然平方数. 解法:比較明显的二分,getsum(int middle)求1-middle有多少个非全然平方数,然后二分.求1-middle的非全然平方数个数能够用总数减掉全然平方数个数.计算全然平方数的个数用容斥: 首先加上n/(2*2)+n/(3*3)+n/(5*5)+n/(7*7)...+...然后减掉出现两次的,然后加上三次的...奇加偶减.这就是mou的原型,用mou数组计算非常easy: 代码: /*****************…
题面 传送门 思路 新姿势get 莫比乌斯容斥 $\sum_{i=1}{n}\mu(i)f(i)$ 这个东西可以把所有没有平方质因子的东西表示出来,还能容斥掉重复的项 证明是根据莫比乌斯函数的定义,显然 于是本题里面,我们二分答案$K$,那么闭区间$[1,K]$中的没有平方质因子的数的个数就是$\sum_{i=1}^{\sqrt{K}}\mu(i)\frac{K}{i^2}$ 然后线性筛一波,单次询问复杂度$O(log_2maxn\sqrt{K})$,$maxn$是二分上界 Code: #inc…
题目大意:求第k个无平方因子数是多少(无视原题干.1也是全然平方数那岂不是一个数也送不出去了? 无平方因子数(square-free number),即质因数分解之后全部质因数的次数都为1的数 首先二分答案 问题转化为求x以内有多少个无平方因子数 依据容斥原理可知 对于√x以内的全部质数 x以内的无平方因子数=无需是不论什么质数的倍数的数的数量(即x)-是至少一个质数平方倍数的数的数量+是至少两个质数平方倍数的数的数量-是至少三个质数平方倍数的数的数量... 我们回去考虑莫比乌斯函数,我们发现每…
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=2440 莫比乌斯...被难倒... 看TJ:http://hzwer.com/4827.html 再看TJ:https://blog.csdn.net/xiefubao/article/details/30567715 努力抄写理解... 代码如下: #include<iostream> #include<cstdio> #include<cstring> #inc…
题意:将n个糖果插入f-1个挡板分成f分(a1,a2,a3...af). 问有多少种分法能够使得gcd(a1,a2,a3...af)=1; 解法.莫比乌斯容斥,首先按1为单位分,这时候有C(n-1,f-1)种,然后去掉gcd不是1的.这时候就规定质因子个数是奇数的就减(mou值为-1),偶数的为加(mou值是+1),然后出现平方数为约数的数mou值为0.这样就做到了容斥,非常巧妙. 容斥时,要注意仅仅用计算是n的约数的数,由于假设不是n的约数,那么gcd里一定不会出现这个因子. 代码: /***…
[BZOJ4833]最小公倍佩尔数(min-max容斥) 题面 BZOJ 题解 首先考虑怎么求\(f(n)\),考虑递推这个东西 \((1+\sqrt 2)(e(n-1)+f(n-1)\sqrt 2)=e(n)+f(n)\sqrt 2\) 拆开之后可以得到:\(e(n)=e(n-1)+2f(n-1),f(n)=f(n-1)+e(n-1)\). 把每一层的\(e\)都给展开,得到:\(\displaystyle f(n)=1+f(n-1)+2\sum_{i=1}^{n-2}f(i)\) 然后差分搞…
G. List Of Integers time limit per test 5 seconds memory limit per test 256 megabytes input standard input output standard output Let's denote as L(x, p) an infinite sequence of integers y such that gcd(p, y) = 1 and y > x (where gcd is the greatest…
Sample Input 6 1 6 2 5 3 4 Sample Output 10 You are given a {1, 2, ..., n}-permutation a[1], a[2], ..., a[n]. How many pairs of integers (i, j) satisfy 1 ≤ i ≤ j ≤ n and gcd(i, j) = gcd(a[i], a[j]) = 1? Here gcd means greatest common divisor. Input F…
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.…
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=6053 题意: 给出一个含 n 个元素的 a 数组, 求 bi <= ai 且 gcd(b1, ..., bn) >= 2 的 b 数组的数目: 思路: 首先想到的方法是枚举 gcd, 对于每个 gcd x 的情况, 将所有 bi / x 连乘, 然后将所有 gcd 的情况累加一下就能的到答案了 . 然而其时间复杂度为 O(t * min(a) * n), 铁定 tle: 对于后面连乘部分是可以优…