神马的容斥原理实在是太神啦!

就是先二分一个数mid,看看有几个满足要求的数比他小。

查看的方法就是容斥原理。。。

res = ((2 ^ 2)倍数个数 - ((2 ^ 2) * (3 ^ 2)倍数个数 + (2 ^ 2) * (5 ^ 2)倍数个数 + ...) + (((2 ^ 2) * (3 ^ 2) * (5 ^ 2)倍数个数 + .....)) + ((3 ^ 2)倍数个数...)

我去。。。这复杂度真的能过= =

 /**************************************************************
Problem: 2986
User: rausen
Language: C++
Result: Accepted
Time:1512 ms
Memory:5688 kb
****************************************************************/ #include <cstdio> using namespace std;
typedef long long ll;
const int N = ; int p[N], cnt;
bool F[N];
ll n; ll find(int f, int i, ll mid) {
ll res = , sqr;
for (; i <= cnt && (sqr = (ll) p[i] * p[i]) <= mid; ++i)
res += (ll) mid / sqr * f + find(-f, i + , mid / sqr);
return res;
} void pre_work(int M) {
int i, j;
for (i = ; i <= M; ++i) {
if (!F[i])
p[++cnt] = i;
for (j = ; i * p[j] <= M && j <= cnt; ++j) {
F[i * p[j]] = ;
if (i % p[j] == ) break;
}
}
} int main() {
pre_work(N);
scanf("%lld", &n);
ll l = , r = (ll) 1e11, mid;
while (l < r) {
mid = (ll) l + r >> ;
if (find(, , mid) < n) l = mid + ;
else r = mid;
}
printf("%lld\n", l);
return ;
}

(p.s. Rank.10)

BZOJ2986 Non-Squarefree Numbers的更多相关文章

  1. Java 位运算2-LeetCode 201 Bitwise AND of Numbers Range

    在Java位运算总结-leetcode题目博文中总结了Java提供的按位运算操作符,今天又碰到LeetCode中一道按位操作的题目 Given a range [m, n] where 0 <= ...

  2. POJ 2739. Sum of Consecutive Prime Numbers

    Sum of Consecutive Prime Numbers Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 20050 ...

  3. [LeetCode] Add Two Numbers II 两个数字相加之二

    You are given two linked lists representing two non-negative numbers. The most significant digit com ...

  4. [LeetCode] Maximum XOR of Two Numbers in an Array 数组中异或值最大的两个数字

    Given a non-empty array of numbers, a0, a1, a2, … , an-1, where 0 ≤ ai < 231. Find the maximum re ...

  5. [LeetCode] Count Numbers with Unique Digits 计算各位不相同的数字个数

    Given a non-negative integer n, count all numbers with unique digits, x, where 0 ≤ x < 10n. Examp ...

  6. [LeetCode] Bitwise AND of Numbers Range 数字范围位相与

    Given a range [m, n] where 0 <= m <= n <= 2147483647, return the bitwise AND of all numbers ...

  7. [LeetCode] Valid Phone Numbers 验证电话号码

    Given a text file file.txt that contains list of phone numbers (one per line), write a one liner bas ...

  8. [LeetCode] Consecutive Numbers 连续的数字

    Write a SQL query to find all numbers that appear at least three times consecutively. +----+-----+ | ...

  9. [LeetCode] Compare Version Numbers 版本比较

    Compare two version numbers version1 and version1.If version1 > version2 return 1, if version1 &l ...

随机推荐

  1. Python的Flask框架应用调用Redis队列数据的方法

    转自:http://www.jb51.net/article/86021.htm 任务异步化 打开浏览器,输入地址,按下回车,打开了页面.于是一个HTTP请求(request)就由客户端发送到服务器, ...

  2. Django框架【基础篇】

    Python的WEB框架有Django.Tornado.Flask 等多种,Django相较与其他WEB框架其优势为:大而全,框架本身集成了ORM.模型绑定.模板引擎.缓存.Session等诸多功能. ...

  3. HTTP cookies 详解(国外一位大牛的文章)

    原文:http://blog.csdn.net/lijing198997/article/details/9378047 HTTP cookies,通常又称作"cookies",已 ...

  4. pandas 取消读取csv时默认第一行为列名

    读取时默认第一行为列名 此时DataFrame的列名为第一行数据: 因为第一行为有效数据,故不可作为列名,要么重新起列名,要么使用默认序列列名: 取消默认第一行为列名 给 pd.read_csv() ...

  5. redhat 6.6 离线安装docker

    本机环境:redhat6.6 uname -a Linux host- -.el6.x86_64 # SMP Tue Sep :: EDT x86_64 x86_64 x86_64 GNU/Linux ...

  6. mapxtreme java学习之路(1)——.dwg转.tab再转.gst详细教程

    [背景] 因为项目的需要,需要在java web 项目中使用到地图,厂家提供的是dwg格式的地图,而我们采用的是mapxtreme java技术,所以先要把dwg格式的地图转成mapxtreme ja ...

  7. phpstorm psr2样式.xml

    将如下内容保存为 .xml 格式 <code_scheme name="Default"> <PHPCodeStyleSettings> <optio ...

  8. MySQL从删库到跑路(三)——SQL语言

    作者:天山老妖S 链接:http://blog.51cto.com/9291927 一.SQL语言简介 1.SQL语言简介 SQL是结构化查询语言(Structured Query Language) ...

  9. Linux centos7 redis安装教程

    1.下载解压 #下载至/home/install(或windows系统下载后上传) mkdir /home/install cd /home/install wget http://124.205.6 ...

  10. 自动化运维工具SaltStack安装配置

    SaltStack是一种全新的基础设置管理方式,部署轻松,在几分钟内可运作起来,扩展性好,很容易管理上万台服务器,速度够快,服务器之间秒级通讯.通过部署SaltStack环境,我们可以在成千上万台服务 ...