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

就是先二分一个数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. MyBatis 内置日志工厂基于运行时自省机制选择合适的日志工具

    mybatis – MyBatis 3 | 日志 http://www.mybatis.org/mybatis-3/zh/logging.html MyBatis 内置日志工厂基于运行时自省机制选择合 ...

  2. proxy,https,git,tortoise git,ssh-agent,ssh-add,ssh,ssl,rsync

    看具体应用了,一般的文件复制使用scp,增量同步使用rsync.rsync的认证可以使用ssh,还可以是rsync自己的密码文件. ssh-keygen -l 察看 fineprint 5.1 通过p ...

  3. Mysql5.6主从复制

    搭建(192.168.1.10 -> 192.168.1.20) 1 master 上执行 阻塞 DMLflush tables with read lock; 记录 File 和 Positi ...

  4. [转载]WorldWind实时确定、更新、初始化和渲染地形和纹理数据

    WorldWind实时确定.更新.初始化和渲染地形和纹理数据 原文链接: http://www.cnblogs.com/rainbow70626/p/5597267.html 当用户点击WorldWi ...

  5. Spring boot 开发WebService遇到的问题之一

    当pom.xml文件中的配置: <artifactId>spring-boot-starter-parent</artifactId><version>2.0.6. ...

  6. Selenium之IE浏览器的启动

    1.下载IEDriverServer.exe文件放至需要的目录中: 2.编写代码 import org.openqa.selenium.WebDriver; import org.openqa.sel ...

  7. Bootstrap table后端分页(ssm版)

    说明bootstrap table可以前端分页,也可以后端sql用limit分页.这里讲的是后端分页,即实用limit.性能较好,一般均用这种源码下载地址:https://git.oschina.ne ...

  8. 牛客国庆集训派对Day6 Solution

    A    Birthday 思路:设置一个源点,一个汇点,每次对$源点对a_i, b_i , a_i 对 b_i 连一条流为1,费用为0的边$ 每个点都再连一条 1, 3, 5, 7, ....的边到 ...

  9. python一段代码 感受一下

    class T():    def aa(self):        write = 1        print '123' class B():            def hehe(self) ...

  10. 基于swing的MySQL可视化界面

    个人记录贴... 代码过烂不宜参考.. 效果展示 1.选择需要打开的数据库,查看数据库下的表. 2.双击打开一个表 3.没有CRUD.... 代码 test-main: import shell.DB ...