**题意:**计算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 大素数计数的更多相关文章

  1. HDU 5901 Count primes 论文题

    Count primes 题目连接: http://acm.split.hdu.edu.cn/showproblem.php?pid=5901 Description Easy question! C ...

  2. HDU 5901 Count primes( Meisell-Lehmer算法模板 )

    链接:传送门 题意:计算 [ 1 , n ] 之间素数的个数,(1 <= n <= 1e11) 思路:Meisell-Lehmer算法是计算超大范围内素数个数的一种算法,原理并不明白,由于 ...

  3. hdu 5901 Count primes (meisell-Lehmer)

    Count primes Time Limit: 12000/6000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Tot ...

  4. hdu 5901 Count primes 素数计数模板

    转自:http://blog.csdn.net/chaiwenjun000/article/details/52589457 计从1到n的素数个数 两个模板 时间复杂度O(n^(3/4)) #incl ...

  5. HDU 5901 Count primes (1e11内的素数个数) -2016 ICPC沈阳赛区网络赛

    题目链接 题意:求[1,n]有多少个素数,1<=n<=10^11.时限为6000ms. 官方题解:一个模板题, 具体方法参考wiki或者Four Divisors. 题解:给出两种代码. ...

  6. [素数个数模板] HDU 5901 Count primes

    #include<cstdio> #include<cmath> using namespace std; #define LL long long ; bool np[N]; ...

  7. 求1-1e11内的素数个数(HDU 5901 Count primes )

    参考链接:https://blog.csdn.net/Dylan_Frank/article/details/54428481 #include <bits/stdc++.h> #defi ...

  8. hdu 5901 Count primes

    题意: 计数区间$[1, n](1 \leq n \leq 10^{11})$素数个数. 分析: 这里只介绍一种动态规划的做法. 首先要说一下[分层思想]在动态规划中非常重要,下面的做法也正是基于这一 ...

  9. HDU 5901 Count primes (2016 acm 沈阳网络赛)

    原题地址:http://acm.hdu.edu.cn/showproblem.php?pid=5901 题意:输入n,输出n以内质数个数 模板题,模板我看不懂,只是存代码用. 官方题解链接:https ...

随机推荐

  1. 使用Python进行AES加密和解密

    摘录于:http://blog.csdn.net/nurke/article/details/77267081 另外参考:http://www.cnblogs.com/kaituorensheng/p ...

  2. NIO 服务端TCP连接管理的方案

    最近做的一个项目需要在服务端对连接端进行管理,故将方案记录于此. 方案实现的结果与背景 因为服务端与客户端实现的是长连接,所以需要对客户端的连接情况进行监控,防止无效连接占用资源. 完成类似于心跳的接 ...

  3. 算法与数据结构实验题 6.4 Summary

    ★实验任务 可怜的 Bibi 丢了好几台手机以后,看谁都像是小偷,他已经在小本本上记 下了他认为的各个地点的小偷数量. 现在我们将 Bibi 的家附近的地形抽象成一棵有根树.每个地点都是树上的 一个节 ...

  4. java定时执行任务(一)

    需求: 经常遇到这样的需求:要求每天执行一次任务,执行任务时间是凌晨3点 实现: 为了便于检测,我假设的是下一分钟执行任务,每10秒重复执行.(对应现实项目:每天3点执行任务.那么就是下一个3点执行任 ...

  5. 一个项目的Makefile编写及调试

    父Makefile 在src目录下包含很多文件夹,那么需要遍历所有的目录执行Makefile,那么给一个在src目录下的Makefile. # 需要排除的目录 exclude_dirs := incl ...

  6. WPF以access为数据库,简单实现一个显示数据和更新数据的实例

    做一个小实例,如下图,

  7. RT-thread main函数分析

    RT-thread系统的main函数位于startup.c文件中. /** * This function will startup RT-Thread RTOS. */ void rtthread_ ...

  8. FZU 1492 地震预测(链表)

    实际上把数组排序一遍加入链表中,再记录好数组原来的数在链表中的位置.我们只需要维护链表的删除操作就可以了. # include <cstdio> # include <cstring ...

  9. 【bzoj4842】[Neerc2016]Delight for a Cat 线性规划与网络流

    题目描述 $n$ 个连续的位置,每个位置可以填入 S 和 E ,第 $i$ 个位置填入 S 可以获得 $s_i$ 的收益,填入 E 可以获得 $e_i$ 的收益.要求每连续的 $k$ 个位置必须包含至 ...

  10. 转:Scipy入门

    Scipy入门 转:http://notes.yeshiwei.com/scipy/getting_started.html 本章节主要内容来自 Getting Started .翻译的其中一部分,并 ...