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 ...
随机推荐
- The Rise of Database Sharding DATABASE SHARDING
w玻璃碎片.0共享 http://www.agildata.com/database-sharding/ The Rise of Database Sharding The concept of Da ...
- php基础:面向对象
一.public.private.protected访问修饰符 public:任何都可以访问(本类.子类.外部都可以访问) protected:本类.子类都可以访问(本类.子类均可访问) privat ...
- stark - 分页、search、actions
一.分页 效果图 知识点 1.分页 {{ showlist.pagination.page_html|safe }} 2.page.py class Pagination(object): def _ ...
- django-mvvm(django的FormObject)
MVVM简介 MVVM模式是Model-View-ViewMode模式的简称.由视图(View).视图模型(ViewModel).模型(Model)三部分组成,结构如下图.通过这三部分实现UI逻辑.呈 ...
- 傅里叶变换 VS 拉普拉斯变换
拉普拉斯变换的公式 傅里叶变换公式 拉普拉斯变换是将时域映射到s plane上,而傅里叶变换实际是将时域 映射在s-plane的虚轴上, 傅里叶变换可以看作拉普拉斯变换 的一种特例 1.推导傅里叶变 ...
- uchome 缓存生成
一.uchome的缓存目录 ---------data此目录要有777权限 (1)模板文件缓存机制 1:在要显示的页面通过include template($name) 语句来包含被编译后的模板文件 ...
- Windows中杀死某个端口的进程
最近写项目,总是出现端口被占用的问题,原来傻傻的把电脑重启一下,终于有一天受不了了,想要想办法解决.刚开始从网上找了好多教程,发现不行.开始自己尝试,终于,成功的将占用端口的进程杀掉.在此记录下过程( ...
- mysql 数据操作 单表查询 group by 注意
GROUP BY 单独使用GROUP BY关键字分组 SELECT post FROM employee GROUP BY post; 注意:我们按照post字段分组,那么select查询的字段只能是 ...
- 203-ReactDOM
一.概述 加载方式: <script> ES6:import ReactDOM from 'react-dom' ES5:var ReactDOM = require('react-dom ...
- Codeforces Round #532 (Div. 2) Solution
A. Roman and Browser 签到. #include <bits/stdc++.h> using namespace std; ]; int get(int b) { ]; ...