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,其中 ...
随机推荐
- iframe下元素定位
1.iframe基础知识: <frameset>生成的框架结构是依赖上级空间尺寸的,它的宽度或者高度必须有一个和上级框架相同.而<iframe>浮动框架可以完全由指定宽度和高度 ...
- win64系统丢失d3dx9d_40.dll问题
在Win64系统中,安装了DXSDK.DX9,却一直显示如上对话框,导致程序运行不起来. 于是我在网上找到了一个d3dx9d_40.dll,覆盖到C:\Windows\System32中,但是问题依然 ...
- 0501-Hystrix保护应用-超时机制、断路器模式简介
一.概述 hystrix对应的中文名字是“豪猪”,豪猪周身长满了刺,能保护自己不受天敌的伤害,代表了一种防御机制,这与hystrix本身的功能不谋而合,因此Netflix团队将该框架命名为Hystri ...
- 吴超老师课程---Hadoop的伪分布安装
1.1 设置ip地址 执行命令 service network restart 验证: ifconfig1.2 关闭防火墙 执行命令 service ip ...
- 百度feed 寒假实习 一面二面(offer)
一面(1小时) 自我介绍,研究方向,本科学校,家乡等等.. 1 介绍了jdd风险登录的比赛,问题背景,建模,特征构建,特征选择,模型等. 个人觉得介绍项目一定要高大上一点,把自己创新或者有创意的点子讲 ...
- Codeforces Round #397 by Kaspersky Lab and Barcelona Bootcamp (Div. 1 + Div. 2 combined) B - Code obfuscation
地址:http://codeforces.com/contest/765/problem/B 题目: B. Code obfuscation time limit per test 2 seconds ...
- EOJ - 3631 Delivery Service 2018.8华师大月赛(树链剖分+贪心)
链接:https://acm.ecnu.edu.cn/contest/103/problem/D/ 题意:给你一棵无向边连接的树,边的权值可以任意互换.有m次运输,每次的花费是点u到v路径上边的权值和 ...
- C语言预处理命令之条件编译(#ifdef,#else,#endif,#if等)
转自:http://www.kuqin.com/language/20090806/66164.html 预处理过程扫描源代码,对其进行初步的转换,产生新的源代码提供给编译器.可见预处理过程先于编译器 ...
- CSS3 文本常用属性
CSS 常用属性 text-shadow属性文字阴影:第一个值背景相对原本文字居左的距离,第二个值据当前文本上方的距离,第三个值清晰度(越小越清晰),第四个值颜色 word-wrap:自动换行,如果是 ...
- python3爬虫全国地址信息
PHP方式写的一团糟所以就用python3重写了一遍,所以因为第二次写了,思路也更清晰了些. 提醒:可能会有502的错误,所以做了异常以及数据库事务处理,暂时没有想到更好的优化方法,所以就先这样吧.待 ...