题意:全然平方数是指含有平方数因子的数。求第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. 将窗口置顶的方法:SetWindowPos、AttachThreadInput、SwitchToThisWindow

    将窗口置顶的方法:SetWindowPos.AttachThreadInput.SwitchToThisWindow [转]http://hi.baidu.com/neil_danky/item/f9 ...

  2. Java学习之String对象为什么是不可变的

    转自:http://www.2cto.com/kf/201401/272974.html,感谢作者的总结 什么是不可变对象? 众所周知, 在Java中, String类是不可变的.那么到底什么是不可变 ...

  3. Android 一个抽奖应用的逆向破解全流程之加固自己应用

    转自: <a href="http://www.pedant.cn/2014/07/22/crack-a-draw-app/">http://www.pedant.cn ...

  4. Android Log工具类

    import java.text.SimpleDateFormat; import java.util.Date; import android.util.Log; public class LogU ...

  5. 【转】linux Centos 6.5 安装桌面环境GNOME

    在某种场合之下,我们使用的Linux还是要选择安装桌面环境的,所以在这里介绍一下如何给没有安装桌面环境的系统安装桌面环境. 以Centos 6.5 为例演示一下如何安装桌面环境. 一.首先查看系统的运 ...

  6. android小知识之意图(intent)

    android中的意图有显示意图和隐式意图两种, 显示意图要求必须知道被激活组件的包和class 隐式意图只需要知道跳转activity的动作和数据,就可以激活对应的组件 A 主activity  B ...

  7. Qt信息隐藏(Q_D/Q_Q)介绍——从二进制兼容讲起

    http://www.cnblogs.com/SkylineSoft/articles/2046404.html

  8. lambda表达式和闭包

    lambda表达式和闭包 熟悉的Javascript或者Ruby的同学,可能对另一个名词:闭包更加熟悉.因为一般闭包的示例代码,长得跟lambda差不多,导致我也在以前很长一段时间对这两个概念傻傻分不 ...

  9. Oracle 局域网布置数据库服务器,客户端连接提示TNS:无监听器的解决实现

    Oracle布置在局域网中的服务器的时候,用本地PL SQL 链接没有丝毫的问题. 但是,如果用远程客户端的PL SQL 链接的时候却出现了“TNS:无监听器”的问题. 首先,就是进行了服务器端的监听 ...

  10. 如何解决Android 5.0中出现的警告:Service Intent must be explicit

    有些时候我们使用Service的时需要采用隐私启动的方式,但是Android 5.0一出来后,其中有个特性就是Service Intent  must be explitict,也就是说从Lollip ...