原题地址:http://acm.hdu.edu.cn/showproblem.php?pid=5901

题意:输入n,输出n以内质数个数

模板题,模板我看不懂,只是存代码用。

官方题解链接:https://async.icpc-camp.org/d/560-2016

/************************************************************
这个模板我一点都不会,代码是从codeforces上抄的,佚名
pi(i)表示i以内质数的个数
*************************************************************/
#include <bits/stdc++.h>
#define ll long long
using namespace std;
ll f[],g[],n;
///f[i]表示 pi(n/i), g[i] 表示 pi(i)
void init(){
ll i,j,m;
for(m=;m*m<=n;++m)f[m]=n/m-;
for(i=;i<=m;++i)g[i]=i-;
for(i=;i<=m;++i){
if(g[i]==g[i-])continue;
for(j=;j<=min(m-,n/i/i);++j){
if(i*j<m)f[j]-=f[i*j]-g[i-];
else f[j]-=g[n/i/j]-g[i-];
}
for(j=m;j>=i*i;--j)g[j]-=g[j/i]-g[i-];
}
}
int main(){
while(scanf("%I64d",&n)!=EOF){
init();
cout<<f[]<<endl;
}
return ;
}

HDU 5901 Count primes (2016 acm 沈阳网络赛)的更多相关文章

  1. HDU 5901 Count primes 论文题

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

  2. hdu 5881 Tea (2016 acm 青岛网络赛)

    原题地址:http://acm.hdu.edu.cn/showproblem.php?pid=5881 Tea Time Limit: 3000/1000 MS (Java/Others)    Me ...

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

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

  4. hdu 5901 Count primes (meisell-Lehmer)

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

  5. 2016 年沈阳网络赛---QSC and Master(区间DP)

    题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=5900 Problem Description Every school has some legend ...

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

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

  7. hdu 5901 Count primes

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

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

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

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

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

随机推荐

  1. Delphi CRC32Verify控件

    unit CRC32Verify; interface uses  Windows, Messages, SysUtils, Classes, Forms; CONST    table:  ARRA ...

  2. ios unit test 工程选择release时候报错Undefined symbols for architecture i386

    Undefined symbols for architecture i386: "_OBJC_CLASS_$_ItemReturn", referenced from: objc ...

  3. 用curl获取https请求时出现错误的处理

    今天一个同事反映,使用curl发起https请求的时候报错:“SSL certificate problem, verify that the CA cert is OK. Details: erro ...

  4. 使用springMVC上传文件

    control层实现功能: @RequestMapping(value="upload2") public String upLoad2(HttpServletRequest re ...

  5. SpringMVC 文本文件下载的配置

    页面: <fieldset> <legend>Download annotator list</legend> <img src="pages/to ...

  6. running android lint has encountered a

    近期写学习android编程的的时候,每次保存.java文件的时候,总会跳出例如以下错误 这个错误不是属于程序错误,把它关掉对于编程没有不论什么影响,但每次见到这个就是不爽,希望大神可以解决一下,谢谢 ...

  7. mongoDB 特别指令用法

    http://apluck.iteye.com/blog/1176160 a.   修改collection集合字段名 参见:http://www.mongodb.org/display/DOCS/U ...

  8. smali语法高亮相关链接

    http://ruby-china.org/topics/8307 http://www.daqianduan.com/4820.html http://www.cnblogs.com/ruochen ...

  9. XCode5无法设置Deployment Target的解决办法

    今天使用XCode5创建新项目的时候发现无法修改Deployment Target,只能选择iOS7,谷歌了一下找到了答案,在这里分享给大家:) 这是由于XCode5默认会选择在64位的环境下运行,在 ...

  10. CentOS7网络桥接模式下配置-经典完备

    原文地址:http://blog.csdn.net/youzhouliu/article/details/51175364 首先要将Vmware设置为桥接模式: 并选择宿主机连接的网路进行桥接: Ce ...