HDU 5901 Count primes 大素数计数
**题意:**计算1~N间素数的个数(N
/** @Date : 2016-11-18-13.59
* @Author : Lweleth (SoungEarlf@gmail.com)
* @Link : https://github.com/
* @Version :
*/
#include <stdio.h>
#include <iostream>
#include <string.h>
#include <algorithm>
#include <utility>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <stack>
#include <math.h>
#include <queue>
//#include<bits/stdc++.h>
#define LL long long
#define MMF(x) memset((x),0,sizeof(x))
#define MMI(x) memset((x), INF, sizeof(x))
using namespace std;
const int INF = 0x3f3f3f3f;
const int N = 1e6+2000;
using namespace std;
//high[i] means pi(n/i),low[i] means pi(i)
LL high[340000];
LL low[340000];
LL n;
LL fun()
{
LL i,m,p,s,x;
for(m = 1; m * m <= n; m++)
high[m] = n/m-1;
for(i = 1;i <= m; i++)
low[i] = i-1;
for(p = 2; p <= m; p++)
{
if(low[p] == low[p-1])
continue;
s = min(n/(p*p),m-1);
for(x = 1; x <= s; x++)
{
if(x*p <= m-1)
high[x] -= high[x*p] - low[p-1];
else
high[x] -= low[n/(x*p)] - low[p-1];
}
for(x = m; x >= p*p; x--)
low[x] -= low[x/p] - low[p-1];
}
}
int main()
{
while(cin>>n)
{
fun();
cout << high[1] << endl;
}
}
HDU 5901 Count primes 大素数计数的更多相关文章
- HDU 5901 Count primes 论文题
		
Count primes 题目连接: http://acm.split.hdu.edu.cn/showproblem.php?pid=5901 Description Easy question! C ...
 - HDU 5901 Count primes( Meisell-Lehmer算法模板 )
		
链接:传送门 题意:计算 [ 1 , n ] 之间素数的个数,(1 <= n <= 1e11) 思路:Meisell-Lehmer算法是计算超大范围内素数个数的一种算法,原理并不明白,由于 ...
 - hdu 5901 Count primes (meisell-Lehmer)
		
Count primes Time Limit: 12000/6000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Tot ...
 - hdu 5901 Count primes 素数计数模板
		
转自:http://blog.csdn.net/chaiwenjun000/article/details/52589457 计从1到n的素数个数 两个模板 时间复杂度O(n^(3/4)) #incl ...
 - HDU 5901 Count primes (1e11内的素数个数) -2016 ICPC沈阳赛区网络赛
		
题目链接 题意:求[1,n]有多少个素数,1<=n<=10^11.时限为6000ms. 官方题解:一个模板题, 具体方法参考wiki或者Four Divisors. 题解:给出两种代码. ...
 - [素数个数模板] HDU 5901 Count primes
		
#include<cstdio> #include<cmath> using namespace std; #define LL long long ; bool np[N]; ...
 - 求1-1e11内的素数个数(HDU 5901 Count primes )
		
参考链接:https://blog.csdn.net/Dylan_Frank/article/details/54428481 #include <bits/stdc++.h> #defi ...
 - hdu 5901 Count primes
		
题意: 计数区间$[1, n](1 \leq n \leq 10^{11})$素数个数. 分析: 这里只介绍一种动态规划的做法. 首先要说一下[分层思想]在动态规划中非常重要,下面的做法也正是基于这一 ...
 - HDU 5901 Count primes (2016 acm 沈阳网络赛)
		
原题地址:http://acm.hdu.edu.cn/showproblem.php?pid=5901 题意:输入n,输出n以内质数个数 模板题,模板我看不懂,只是存代码用. 官方题解链接:https ...
 
随机推荐
- [leetcode-667-Beautiful Arrangement II]
			
Given two integers n and k, you need to construct a list which contains n different positive integer ...
 - Beta版本软件使用说明
			
北京航空航天大学计算机学院 远航1617 小组 产品版本: Beta版本 产品名称:Crawling is going on 文档作者:杨帆 文档日期:2013/12/24 1. 引言 1.1 ...
 - 常用算法Java实现之选择排序
			
选择排序算法在每一步中选取最小值来重新排序,通过选择和交换来实现排序. 具体流程如下: 1.首先从原数组中选择最小的1个数据,将其置于第一个位置. 2.然后从剩下的数据中再选择其中最小的一个数据,并将 ...
 - freefcw/hustoj Install Guide
			
First of all, this version hustoj is a skin and improved for https://code.google.com/p/hustoj/. So t ...
 - HttpServletRequest和HttpServletResponse实例
			
先看一下web.xml文件配置: <?xml version="1.0" encoding="UTF-8"?> <web-app versio ...
 - LintCode-378.将二叉查找树转换成双链表
			
将二叉查找树转换成双链表 将一个二叉查找树按照中序遍历转换成双向链表. 样例 给定一个二叉查找树: 返回 1<->2<->3<->4<->5. 标签 链 ...
 - LintCode-374.螺旋矩阵
			
螺旋矩阵 给定一个包含 m x n 个要素的矩阵,(m 行, n 列),按照螺旋顺序,返回该矩阵中的所有要素. 样例 给定如下矩阵: [ [ 1, 2, 3 ], [ 4, 5, 6 ...
 - mysql,oracle,sql server中的默认事务隔离级别查看,更改
			
未提交读(隔离事务的最低级别,只能保证不读取物理上损坏的数据) 已提交读(数据库引擎的默认级别) 可重复读 可序列化(隔离事务的最高级别,事务之间完全隔离) 可串行化比较严谨,级别高; MySQL m ...
 - poj1474  Video Surveillance
			
题意:求多边形的内核,即:在多边形内部找到某个点,使得从这个点能不受阻碍地看到多边形的所有位置. 只要能看到所有的边,就能看到所有的位置.那么如果我们能够在多边形的内部的点x看到某条边AB,这个点x一 ...
 - vdbench-自动化测试脚本
			
#!/usr/bin/python # -*- coding:utf8 -*- import sys import commands TEST_CONF=""" hd=d ...