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

就是先二分一个数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. 介绍一个Redis的WEB 客户端

    http://webd.is/ $ git clone git://github.com/nicolasff/webdis.git                $ cd webdis$ make$ ...

  2. Python开发【Tornado】:异步Web服务(一)

    异步Web服务 前言: 到目前为止,我们已经看到了许多使Tornado成为一个Web应用强有力框架的功能.它的简单性.易用性和便捷性使其有足够的理由成为许多Web项目的不错的选择.然而,Tornado ...

  3. 信号(Django信号、Flask信号、Scrapy信号)

    简介 Django.Flask.scrapy都包含了一个“信号分配器”,使得当一些动作在框架的其他地方发生的时候,解耦的应用可以得到提醒. 通俗来讲,就是一些动作发生的时候,信号允许特定的发送者去提醒 ...

  4. 求连续出现5次以上的值,并且取第5次所在id

    关键字:求连续出现5次以上的值,并且取第5次所在id 关键字:求在某列连续出现N次值的的数据,并且取第M次出现所在行 需求,求连续出现5次以上的值,并且取第5次所在id SQL SERVER: --测 ...

  5. git-【一】概述安装

    一:Git是什么? Git是目前世界上最先进的分布式版本控制系统. 二:SVN与Git的最主要的区别? SVN是集中式版本控制系统,版本库是集中放在中央服务器的,而干活的时候,用的都是自己的电脑,所以 ...

  6. python模块之signal信号

    简介 作用:发送和接收异步系统信号 信号是一个操作系统特性,它提供了一个途径可以通知程序发生了一个事件并异步处理这个事件.信号可以由系统本身生成,也可以从一个进程发送到另一个进程. 由于信号会中断程序 ...

  7. 【Cocos2dx3.x Lua】图片异步加载

    一.说明     异步加载就是把消耗程序时间比较大的加载操作放到其他线程中,待加载完毕后通过回调函数的方式通知主线程.   addImageAsync函数实现(Cocos2dx 3.3) Link:  ...

  8. Entity Framework With Oracle(转)

    虽然EF6都快要出来了,但是对于Oracle数据库,仍然只能用DB first和Model First来编程,不能用Code First真是一个很大的遗憾啊. 好了,废话少说,我们来看看EF中是如何用 ...

  9. SQL 处理排序空值

    ①oracle默认排序空值在后面 如果想要排序空值在前面可用关键字 NULLS FIRST, 排序空值在后面也有关键字NULLS LAST ②sqlserver默认排序空值在前面 如果想要排序时空值在 ...

  10. laravel + html ajax 多表单字段和图片一起上传

    $("#article_push").on('click', function (e){ e.preventDefault(); var stylestr = $('#summer ...