模板题,不过好像有点问题,当a==1的时候,答案把一也算进去了,要减去

#include<map>
#include<set>
#include<cmath>
#include<queue>
#include<stack>
#include<vector>
#include<cstdio>
#include<cassert>
#include<iomanip>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
#define pi acos(-1.0)
#define ll long long
#define mod 1000000007
#define ls l,m,rt<<1
#define rs m+1,r,rt<<1|1
#pragma comment(linker, "/STACK:1024000000,1024000000") using namespace std; const double g=10.0,eps=1e-;
const int N=+,maxn=+,inf=0x3f3f3f; bool prime[N],primesmall[N];
ll seg_prime(ll a,ll b)
{
memset(prime,,sizeof prime);
for(ll i=;i*i<b;i++)primesmall[i]=;
for(ll i=;i<=b-a;i++)prime[i]=;
for(ll i=;i*i<b;i++)
{
if(primesmall[i])
{
for(ll j=*i;j*j<b;j+=i)primesmall[j]=;
for(ll j=max((ll),(a+i-)/i)*i;j<=b;j+=i)prime[j-a]=;
}
}
ll ans=;
for(ll i=;i<=b-a;i++)
if(prime[i])
ans++;
return ans;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie();
ll t,cnt=;
cin>>t;
while(t--){
ll a,b;
cin>>a>>b;
if(a==)cout<<"Case "<<++cnt<<": "<<seg_prime(a,b)-<<endl;
else cout<<"Case "<<++cnt<<": "<<seg_prime(a,b)<<endl;
}
return ;
}
/*********************
9
2 36
3 73
3 11
1 1
1 2
2147383647 2147483647
23990500 24000500
24000501 24100501
23999500 24010501
*********************/

lightoj1197区间素数筛的更多相关文章

  1. LightOj 1197 Help Hanzo 区间素数筛

    题意: 给定一个区间a,b,a-b>=100000,1<=a<=b<=231,求出给定a,b区间内的素数的个数 区间素数筛 (a+i-1)/ ii向上取整,当a为 i 的整数倍 ...

  2. POJ2689:Prime Distance(大数区间素数筛)

    The branch of mathematics called number theory is about properties of numbers. One of the areas that ...

  3. 题解报告:poj 2689 Prime Distance(区间素数筛)

    Description The branch of mathematics called number theory is about properties of numbers. One of th ...

  4. poj 2689 区间素数筛

    The branch of mathematics called number theory is about properties of numbers. One of the areas that ...

  5. Light oj 1197 - Help Hanzo (素数筛技巧)

    题目链接:http://lightoj.com/volume_showproblem.php?problem=1197 给你a和b求a到b之间的素数个数. 先在小区间素数筛,大区间就用类似素数筛的想法 ...

  6. Help Hanzo (素数筛+区间枚举)

    Help Hanzo 题意:求a~b间素数个数(1 ≤ a ≤ b < 231, b - a ≤ 100000).     (全题在文末) 题解: a~b枚举必定TLE,普通打表MLE,真是头疼 ...

  7. LightOj 1197 - Help Hanzo(分段筛选法 求区间素数个数)

    题目链接:http://lightoj.com/volume_showproblem.php?problem=1197 题意:给你两个数 a b,求区间 [a, b]内素数的个数, a and b ( ...

  8. LightOJ 1197 LightOJ 1197(大区间素数筛选)

    http://lightoj.com/volume_showproblem.php?problem=1197 题目大意: 就是给你一个区间[a,b]让你求这个区间素数的个数 但a.b的值太大没法直接进 ...

  9. hdu6069(简单数学+区间素数筛法)

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=6069 题意: 给出 l, r, k.求:(lambda d(i^k))mod998244353,其中 ...

随机推荐

  1. 微信js获取地理位置

    1.绑定域名 先登录微信公众平台进入“公众号设置”的“功能设置”里填写“JS接口安全域名”. 备注:登录后可在“开发者中心”查看对应的接口权限. 2.引入js文件 <script type=&q ...

  2. 我的Android进阶之旅------>Android通用流行框架大全

    Android通用流行框架大全 缓存 图片加载 图片处理 网络请求 网络解析 数据库 依赖注入 图表 后台处理 事件总线 响应式编程 Log框架 测试框架 调试框架 性能优化 本文转载于lavor的博 ...

  3. json的相关操作

    最近对json的操作不是很理解 定义: JSON(JavaScript Object Notation, JS 对象标记) 是一种轻量级的数据交换格式. 它基于 ECMAScript (w3c制定的j ...

  4. Android “swipe” vs “fling”

    onFling will get executed when a user makes a "fling" motion, and said motion has a veloci ...

  5. Selenium 安装与卸载

    安装: 在cmd中键入pip install selenium==3.6.0(等号后面的为版本号),并点击回车,当出现Successfully installed selenium-3.6.0即表示已 ...

  6. 安装RabbitMQ3.6.10报错:{error,{missing_dependencies,[crypto,ssl],

    参考https://blog.csdn.net/u010739551/article/details/80848993 如果安装上篇博文安装则可避免这种情况 CentOS6.7安装RabbitMQ3. ...

  7. 对ASIHTTPRequest的封装

    版权声明:本文为博主原创文章.未经博主同意不得转载. https://blog.csdn.net/quanqinayng/article/details/37659751 .h文件  // // Ht ...

  8. Node.js API学习笔记(一)

    此文章已经发表于本人博客. Terminal(终端) 说起这个使用过linux系统的兄台一般都会知道的,本人理解:类似Putty这些ssh工具通过 软件来实现远程控制主机,对于我们使用者来说,它会显示 ...

  9. ArcEngine开发中“错误类型"****"未定义构造函数”

    from:http://blog.csdn.net/mengdong_zy/article/details/8990593 问题 在ArcEngine开发的时候,在编译时,发现出现这样的错误,出错的地 ...

  10. python报错 TypeError: string indices must be integers

    所以在读取字典的时候,最好先判断类型,然后再查看它是否已经有这样的属性: type(mydict) == type({})             #检查不是字典 如果是字典,再看看有没有这样的属性: ...