BZOJ2986 Non-Squarefree Numbers
神马的容斥原理实在是太神啦!
就是先二分一个数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的更多相关文章
- Java 位运算2-LeetCode 201 Bitwise AND of Numbers Range
在Java位运算总结-leetcode题目博文中总结了Java提供的按位运算操作符,今天又碰到LeetCode中一道按位操作的题目 Given a range [m, n] where 0 <= ...
- POJ 2739. Sum of Consecutive Prime Numbers
Sum of Consecutive Prime Numbers Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 20050 ...
- [LeetCode] Add Two Numbers II 两个数字相加之二
You are given two linked lists representing two non-negative numbers. The most significant digit com ...
- [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 ...
- [LeetCode] Count Numbers with Unique Digits 计算各位不相同的数字个数
Given a non-negative integer n, count all numbers with unique digits, x, where 0 ≤ x < 10n. Examp ...
- [LeetCode] Bitwise AND of Numbers Range 数字范围位相与
Given a range [m, n] where 0 <= m <= n <= 2147483647, return the bitwise AND of all numbers ...
- [LeetCode] Valid Phone Numbers 验证电话号码
Given a text file file.txt that contains list of phone numbers (one per line), write a one liner bas ...
- [LeetCode] Consecutive Numbers 连续的数字
Write a SQL query to find all numbers that appear at least three times consecutively. +----+-----+ | ...
- [LeetCode] Compare Version Numbers 版本比较
Compare two version numbers version1 and version1.If version1 > version2 return 1, if version1 &l ...
随机推荐
- 【PHP】善用php-fpm的慢执行日志slow log,分析php性能问题
(转)善用php-fpm的慢执行日志slow log,分析php性能问题 众所周知,mysql有slow query log,根据慢查询日志,我们可以知道那些sql语句有性能问题.作为mysql的好 ...
- 1.2 Getting Started--Naming Conventions(命名约定)
Ember.js使用一个运行时解析器去连接你的对象而没有很多样板文件.作为一个开发者,如果你把code放到约定好的位置这个解析器会自动工作. 一.The Application 1. 当你 ...
- 爬虫概要及web微信请求分析
一.爬虫概要 1.网络爬虫是什么 百度百科:网络爬虫(又被称为网页蜘蛛,网络机器人,在FOAF社区中间,更经常的称为网页追逐者),是一种按照一定的规则,自动地抓取万维网信息的程序或者脚本.另外一些不常 ...
- pug 在线文档
https://pugjs.org/zh-cn/api/getting-started.html
- Python笔记 #18# Pandas: Grouping
10 Minutes to pandas 引 By “group by” we are referring to a process involving one or more of the foll ...
- 20145312 《网络对抗》PC平台逆向破解:注入shellcode和 Return-to-libc 攻击实验
20145312 <网络对抗>PC平台逆向破解:注入shellcode和 Return-to-libc 攻击实验 注入shellcode 实验步骤 1. 准备一段Shellcode 2. ...
- 20145322何志威《网络对抗》Exp2 后门原理与实践
基础问题回答 1 例举你能想到的一个后门进入到你系统中的可能方式? 在网上下载盗版软件时捆绑的后门程序. 不小心进入钓鱼网站. 2 例举你知道的后门如何启动起来(win及linux)的方式? Wind ...
- 20145311实验四 "Android开发基础"
20145311实验四 "Android开发基础" 程序设计过程 实验内容 ·安装Android Studio·运行安卓AVD模拟器·使用安卓运行出虚拟手机并显示HelloWorl ...
- 【javascript】数据结构-队列
<!DOCTYPE html> <html> <head> <title>queue</title> <meta charset=&q ...
- HDU 4272 LianLianKan (状压DP+DFS)题解
思路: 用状压DP+DFS遍历查找是否可行.假设一个数为x,那么他最远可以消去的点为x+9,因为x+1~x+4都能被他前面的点消去,所以我们将2进制的范围设为2^10,用0表示已经消去,1表示没有消去 ...