lightoj1197区间素数筛
模板题,不过好像有点问题,当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区间素数筛的更多相关文章
- LightOj 1197 Help Hanzo 区间素数筛
题意: 给定一个区间a,b,a-b>=100000,1<=a<=b<=231,求出给定a,b区间内的素数的个数 区间素数筛 (a+i-1)/ ii向上取整,当a为 i 的整数倍 ...
- POJ2689:Prime Distance(大数区间素数筛)
The branch of mathematics called number theory is about properties of numbers. One of the areas that ...
- 题解报告:poj 2689 Prime Distance(区间素数筛)
Description The branch of mathematics called number theory is about properties of numbers. One of th ...
- poj 2689 区间素数筛
The branch of mathematics called number theory is about properties of numbers. One of the areas that ...
- Light oj 1197 - Help Hanzo (素数筛技巧)
题目链接:http://lightoj.com/volume_showproblem.php?problem=1197 给你a和b求a到b之间的素数个数. 先在小区间素数筛,大区间就用类似素数筛的想法 ...
- Help Hanzo (素数筛+区间枚举)
Help Hanzo 题意:求a~b间素数个数(1 ≤ a ≤ b < 231, b - a ≤ 100000). (全题在文末) 题解: a~b枚举必定TLE,普通打表MLE,真是头疼 ...
- LightOj 1197 - Help Hanzo(分段筛选法 求区间素数个数)
题目链接:http://lightoj.com/volume_showproblem.php?problem=1197 题意:给你两个数 a b,求区间 [a, b]内素数的个数, a and b ( ...
- LightOJ 1197 LightOJ 1197(大区间素数筛选)
http://lightoj.com/volume_showproblem.php?problem=1197 题目大意: 就是给你一个区间[a,b]让你求这个区间素数的个数 但a.b的值太大没法直接进 ...
- hdu6069(简单数学+区间素数筛法)
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=6069 题意: 给出 l, r, k.求:(lambda d(i^k))mod998244353,其中 ...
随机推荐
- Jconsole监控tomcat 的JVM内存的设置
主要参考这位仁兄的文章 http://elf8848.iteye.com/blog/471676 照做后发现还是不行,原来是Linux服务器配置了多块网卡,在设置 Djava.rmi.server. ...
- js事件委托和jQuery事件绑定on , off , one , bind , unbind , die
一. 事件委托什么是事件委托?用现实中的理解就是:有100 个学生同时在某天中午收到快递,但这100 个学生不可能同时站在学校门口等,那么都会委托门卫去收取,然后再逐个交给学生.而在jQuery 中, ...
- C#HTML与UBB(纯文本)之间的转换
private string HtmlToUBB(string _Html) { _Html = Regex.Replace(_Html,"<br ...
- Android图片加载框架Picasso最全使用教程1
Picasso介绍 Picasso是Square公司开源的一个Android图形缓存库 A powerful image downloading and caching library for And ...
- redhat 9.0安装完不能上网解决办法(补) - 并附上redhat9.0 下载链接
昨天一位网友Q我,说我的开发环境搭建教程按步骤最后上不了网怎么解决我才突然想起9.0版本在VM7,8中存在问题,于是今天我就简单说下解决的方法. 由于本人习惯使用redhat 9.0版本所以到现在还是 ...
- c#的yield return
4.1 迭代器块 一个迭代器块(iterator block)是一个能够产生有序的值序列的块.迭代器块和普通语句块的区别就是其中出现的一个或多个yield语句. yield return语句产生迭代的 ...
- $git学习总结系列(4)——gitignore文件
有时候工作区中会有我们创建的一些密码配置文件,或者自动生成的一些临时文件,比如python代码编译产生的.pyc文件和java代码编译产生的.class文件等,我们在提交代码的时候没有必要把这些文件也 ...
- sql统计上周销售量的起止时间
开始日期: >select DATEADD(Day, 1 - DATEPART(Weekday,CONVERT(varchar(10), GETDATE() - 7, 120)), CONVER ...
- 把 html标签转化为 html标签代码
HttpUtility.HtmlEncode(table.Rows[0]["footnote"].ToString());
- Linux常用监控命令
A goal is a dream with a deadline. Much effort, much prosperity. 1.IOSTAT命令 此命令安装包为sysstat 可用yu ...