题意:全然平方数是指含有平方数因子的数。求第ki个非全然平方数。

解法:比較明显的二分,getsum(int middle)求1-middle有多少个非全然平方数,然后二分。求1-middle的非全然平方数个数能够用总数减掉全然平方数个数。计算全然平方数的个数用容斥:

首先加上n/(2*2)+n/(3*3)+n/(5*5)+n/(7*7)...+...然后减掉出现两次的,然后加上三次的...奇加偶减。这就是mou的原型,用mou数组计算非常easy;

代码:

/******************************************************
* @author:xiefubao
*******************************************************/
#pragma comment(linker, "/STACK:102400000,102400000")
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <queue>
#include <vector>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <stack>
#include <string.h>
//freopen ("in.txt" , "r" , stdin);
using namespace std; #define eps 1e-8
#define zero(_) (abs(_)<=eps)
const double pi=acos(-1.0);
typedef unsigned long long LL;
const int Max=100010;
const LL INF=2e16+7; LL mou[Max];
void init()
{
for(LL i=2; i<Max; i++)
{
if(!mou[i])
{
mou[i]=i;
for(LL j=i*i; j<Max; j+=i)
mou[j]=i;
}
}
mou[1]=1;
for(int i=2; i<Max; i++)
{
if(i/mou[i]%mou[i]==0) mou[i]=0;
else mou[i]=-mou[i/mou[i]];
}
}
int k;
LL getnum(LL middle)
{
LL ans=0;
for(LL i=1; i*i<=middle; i++)
{
ans+=mou[i]*(middle/(i*i));
}
return ans;
}
int main()
{
init();
int t;
cin>>t;
while(t--)
{
scanf("%d",&k);
LL left=1,right=INF;
while(left<=right)
{
int middle=(left+right)/2;
if(getnum(middle)<k)
left=middle+1;
else
right=middle-1;
}
cout<<left<<'\n';
}
return 0;
}

BZOJ2440(全然平方数)二分+莫比乌斯容斥的更多相关文章

  1. [中山市选2011][bzoj2440] 完全平方数 [二分+莫比乌斯容斥]

    题面 传送门 思路 新姿势get 莫比乌斯容斥 $\sum_{i=1}{n}\mu(i)f(i)$ 这个东西可以把所有没有平方质因子的东西表示出来,还能容斥掉重复的项 证明是根据莫比乌斯函数的定义,显 ...

  2. BZOJ 2440 中山市选2011 全然平方数 二分答案+容斥原理+莫比乌斯反演

    题目大意:求第k个无平方因子数是多少(无视原题干.1也是全然平方数那岂不是一个数也送不出去了? 无平方因子数(square-free number),即质因数分解之后全部质因数的次数都为1的数 首先二 ...

  3. bzoj2440 [中山市选2011]完全平方数——莫比乌斯+容斥

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=2440 莫比乌斯...被难倒... 看TJ:http://hzwer.com/4827.htm ...

  4. CF(439E - Devu and Birthday Celebration)莫比乌斯容斥

    题意:将n个糖果插入f-1个挡板分成f分(a1,a2,a3...af). 问有多少种分法能够使得gcd(a1,a2,a3...af)=1; 解法.莫比乌斯容斥,首先按1为单位分,这时候有C(n-1,f ...

  5. 【BZOJ4833】最小公倍佩尔数(min-max容斥)

    [BZOJ4833]最小公倍佩尔数(min-max容斥) 题面 BZOJ 题解 首先考虑怎么求\(f(n)\),考虑递推这个东西 \((1+\sqrt 2)(e(n-1)+f(n-1)\sqrt 2) ...

  6. Educational Codeforces Round 37 G. List Of Integers (二分,容斥定律,数论)

    G. List Of Integers time limit per test 5 seconds memory limit per test 256 megabytes input standard ...

  7. HihoCoder - 1867: GCD (莫比乌斯容斥)

    Sample Input 6 1 6 2 5 3 4 Sample Output 10 You are given a {1, 2, ..., n}-permutation a[1], a[2], . ...

  8. CodeForces - 803F: Coprime Subsequences(莫比乌斯&容斥)

    Let's call a non-empty sequence of positive integers a1, a2... ak coprime if the greatest common div ...

  9. hdu6053(莫比乌斯+容斥+分块)

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=6053 题意: 给出一个含 n 个元素的 a 数组, 求 bi <= ai 且 gcd(b1, ...

随机推荐

  1. leetcode Climbing Stairs python

    class Solution(object): def climbStairs(self, n): """ :type n: int :rtype: int " ...

  2. This 关键字和变量作用域

    public class Number {     int count; public void method01(){ //    int count=3;     count=3; //    t ...

  3. C++の友元の例

    #include<iostream> #include<cmath> using namespace std; class Point { public: Point(doub ...

  4. C语言与管道

    int main() { int s; int n; float avg; scanf("%d,%d",&s,&n); //特别注意的地方 // scanf(&qu ...

  5. php学习笔记(1)

    1.引用文件的方法有两种:require 及 include require 的使用方法如 require("MyRequireFile.php"); .这个函数通常放在 PHP ...

  6. pyVmomi入门

    简要说明 pyVmomi is the Python SDK for the VMware vSphere API that allows you to manage ESX, ESXi, and v ...

  7. Umbraco隐藏属性

    Umbraco默认的Url地址,是根据Node路径来默认显示的,因此使用中文的话比较尴尬. 网上有传的方法,是修改源码,来实现Url的重写. 但实际大可不必如此麻烦,只需要增加两个类型为Textstr ...

  8. listview 的onitemlongclick阿和onitemclick冲突,item中还有button的点击事件

    listview里面item有button的,button要设置 android:focusable="false"  ,listview里面如果设置了 onitemlongcli ...

  9. flume 自己定义 hbase sink 类

    參考(向原作者致敬) http://ydt619.blog.51cto.com/316163/1230586 https://blogs.apache.org/flume/entry/streamin ...

  10. 延迟N秒执行某个方法

    [self performSelector:<#(nonnull SEL)#> withObject:<#(nullable id)#> afterDelay:<#(NS ...