模板题,不过好像有点问题,当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. Python 网络编程了解

    阅读目录 一: 网络编程socket http://www.cnblogs.com/zhoujunhao/articles/7592671.html 二: TCP粘包处理 http://www.cnb ...

  2. nfs服务、crond服务

    一.nfs服务 NFS 是Network File System的缩写,即网络文件系统.一种使用于分散式文件系统的协定,由Sun公司开发,于1984年向外公布.功能是通过网络让不同的机器.不同的操作系 ...

  3. day2 笔记

    while 条件:           # 循环体       # 如果条件为真,那么循环体则执行     # 如果条件为假,那么循环体不执行         循环中止语句 如果在循环的过程中,因为某 ...

  4. SvsUtil.exe生成服务文件

    在程序中调用某个 WCF Services 一般按照如下步骤进行: 生成对应 Service 的代理类.程序创建该代理类实例,访问指定方法. 生成代理类 可通过在 Visual Studio 中针对某 ...

  5. WinForm下的Nhibernate+Spring.Net的框架配置文件

    1.先将配置文件放到如下:<?xml version="1.0" encoding="utf-8"?> <configuration> ...

  6. linux 清理cache中的内存

    1. sync 2. sysctl -w vm.drop_caches=1

  7. Linux 进程管理 vmstat、top、pstree命令

    vmstat命令:监控系统资源 vmstat 是 Linux 中的一个综合性能分析工具,可以用来监控 CPU 使用.进程状态.内存使用.虚拟内存使用.磁盘输入/输出状态等信息.vmstat 命令格式如 ...

  8. jQuery音乐播放器jPlayer

    在线演示 本地下载

  9. kali 2016:mount ntfs 分区只读 --Falling back to read-only mount because the NTFS partition is in an unsafe state.

    mount ntfs 分区 mount /dev/sdb1 /mnt/d 提示: The disk contains an unclean file system (0, 0).Metadata ke ...

  10. 做为 Apple Store App 独立开发者,你要搞限时促销,为你的应用生成激活码(或者优惠券),使用 Python 如何生成 200 个激活码(或者优惠券)?

    import random import string def GenKey(length): chars = string.ascii_letters + string.digits return ...