Help Hanzo LightOJ - 1197(区间筛素数模板题)

关于MOS管栅极和栅介质(氧化物)的材料选择 大概解释了高K材料作为栅介质的好处,以及为什么会带来好处,同时引出了金属栅的优点,总结了使用高K材料和金属栅的原因。 阅读详情

Help Hanzo LightOJ - 1197

Amakusa, the evil spiritual leader has captured the beautiful princess Nakururu. The reason behind this is he had a little problem with Hanzo Hattori, the best ninja and the love of Nakururu. After hearing the news Hanzo got extremely angry. But he is clever and smart, so, he kept himself cool and made a plan to face Amakusa.

Before reaching Amakusa's castle, Hanzo has to pass some territories. The territories are numbered as a, a+1, a+2, a+3 ... b. But not all the territories are safe for Hanzo because there can be other fighters waiting for him. Actually he is not afraid of them, but as he is facing Amakusa, he has to save his stamina as much as possible.

He calculated that the territories which are primes are safe for him. Now given a and b he needs to know how many territories are safe for him. But he is busy with other plans, so he hired you to solve this small problem!

Input

Input starts with an integer T (≤ 200), denoting the number of test cases.

Each case contains a line containing two integers a and b (1 ≤ a ≤ b < 231, b - a ≤ 100000).

Output

For each case, print the case number and the number of safe territories.

Sample Input

3

2 36

3 73

3 11

Sample Output

Case 1: 11

Case 2: 20

Case 3: 4

Note

A number is said to be prime if it is divisible by exactly two different integers. So, first few primes are 2, 3, 5, 7, 11, 13, 17, ...

模板
code:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAX = 1e5+10;
const int MAX_INTERVAL = 2e5+100;
bool is_prime[MAX_INTERVAL];
bool is_prime_small[MAX];
int segment_sieve(ll a,ll b){
    for(int i = 0; (ll)i * i <= b; i++) is_prime_small[i] = true;
    for(int i = 0; i <= b - a; i++) is_prime[i] = true;

    for(int i = 2; (ll)i * i <= b; i++){
       if(is_prime_small[i]){
          for(int j = 2 * j; (ll)j * j <= b; j += i)
            is_prime_small[j] = false;
          for(ll j = max(2LL,(a+i-1)/i)*i; j <= b; j += i)
            is_prime[j-a] = false;
      //找到a-b范围内第一个i到倍数将其划去,记录到时候仍然记录离散化后的数组位置
       }
    }
    int ans = 0;
    for(int i = 0; i <= b-a; i++){
       if(is_prime[i]) ans++;
    }
    return ans;
}
int main(){
   int T,cas = 0;
   scanf("%d",&T);
   while(T--){
      ll a,b;
      scanf("%lld%lld",&a,&b);
      int ans = segment_sieve(a,b);
      if(a == 1) ans--;
      printf("Case %d: %d\n",++cas,ans);
   }
   return 0;
}
解锁RK3588+RTL8211F:千兆以太网PHY调优秘籍 本文探讨了RK3588芯片搭配RTL8211F千兆以太网PHY的优化方案。文章首先分析了RK3588和RTL8211F的硬件特性,指出时序问题可能源于时钟信号不稳定、传输延迟和PHY内部逻辑延迟。针对这些问题,提出了选用高质量时钟源、优化PCB布线等时序优化策略,以及合理配置硬件参数、优化网络协议等延迟优化方法。在配置实践部分,详细介绍了硬件连接规范和软件配置步骤,并建议使用Iperf、Ping等工具进行性能测试。最后总结了常见问题解决方案,展望了未来PHY芯片和传输技术的发展趋势。这些优化措施可显著提升网 阅读详情

相关推荐

无感健康监测的未来:毫米波雷达如何重新定义睡眠科技与居家养老

毫米波雷达技术正重新定义无感健康监测,特别是在睡眠科技与居家养老领域。通过精准监测呼吸、心率和体动,无需穿戴设备即可实现临床级精度。结合合宙Air700E开发板,构建了完整的远程看护解决方案,为老年人提供跌倒检测、异常报警等安全保障,同时保护用户隐私。

cake8的博客 566

kuangbin 数论基础 M题

M - Help HanzoAmakusa, the evil spiritual leader has captured the beautiful princess Nakururu. The reason behind this is he had a little problem with Hanzo Hattori, the best ninja and the love of Nakur

wtml 364

Halcon频域滤波实战:5分钟搞定傅里叶变换与功率谱分析(附完整代码)

本文提供Halcon频域滤波的实战指南,重点讲解如何利用傅里叶变换与功率谱分析快速解决图像处理难题。通过核心算子fft_image和power_real,演示了从空间域转换到频域、分析功率谱以定位周期性噪声,并构造滤波器进行精准去除的完整流程,附有可直接运行的代码示例。

docker8compose的博客 215

LightOJ-1197 Help Hanzo(区间筛板子题)

Help Hanzo Amakusa, the evil spiritual leader has captured the beautiful princess Nakururu. The reason behind this is he had a little problem with Hanzo Hattori, the best ninja and the love of Nakururu. After hearing the news Hanzo got extremely angry. But

qq_43461168的博客 358

Python Selenium调用IE11报错全解析:从环境配置到稳定运行

在Web自动化测试领域,Selenium作为主流的跨浏览器测试框架,其核心原理是通过WebDriver协议与不同浏览器的驱动程序进行通信,实现对浏览器行为的模拟与控制。这一技术为软件测试的自动化、回归测试的效率提升提供了重要价值,广泛应用于金融、政务等对遗留系统兼容性要求高的行业场景。然而,当技术栈涉及过时的浏览器如IE11时,环境配置的复杂性显著增加,特别是Python与Selenium的组合常遭遇驱动兼容性、安全设置等挑战。本文聚焦于解决Python Selenium驱动IE11时的典型报错问题,深入剖

weixin_28834765的博客 322

中国 it 集成商 主要有哪些 主要做什么工作

既要懂技术(云计算/AI),又要吃透行业(金融/政务)。:用国产化方案(麒麟OS+达梦数据库)替换Oracle/Windows。:如为银行搭建数据中心(采购华为服务器+思科交换机)。:数据中心监控、故障处理(如华胜天成服务国家电网)。:核心交易系统(如中科软为保险公司开发精算平台)。:智慧城市(如太极股份承建“一网通办”政务平台)。:HIS医院信息系统(如东华软件的电子病历系统)。:硬件透明化(如服务器价格战)压缩集成毛利。:工厂设备联网(新华三的工业互联网平台)。

hxsln11的博客 3035

LightOJ 1197 Help Hanzo

题目链接:点我Amakusa, the evil spiritual leader has captured the beautiful princess Nakururu. The reason behind this is he had a little problem with Hanzo Hattori, the best ninja and the love of Nakururu. Af

wood 382

UE5入门第二周总结:基于蓝图的国际象棋的实现

在C++的学习中,这是一个入门级别的项目。我们的目标是灵活运用蓝图的特性和强大的可视化功能,做出这一入门级项目的同时,思考如何优化并改进算法,并尽可能的用面向对象的方法实现,用蓝图中的继承和多态简化编码过程。

YoungeYang的博客 1259

Help Hanzo 素数打表进阶(大数据区间打表)

题意:求a~b之间的素数;(1 难点:数据太大,素数打表会TLE,枚举会MLE; 解题关键:b-a 方法:素数打表小部分(1e6),然后用已打表素数去拓展所给区间的素数,用v[j-a](a #include #include #include #include using namespace std; typedef long long ll; const int N=1e6+5; int

Big_Rui的博客 729

Open3D:Win10 + VS2017配置Open3D(C++、python)

一、下载源码 地址:https://github.com/intel-isl/Open3D 1.1 克隆源码【笔者的源码路径为D:\Open3D\Open3D】 1.2 切换版本【笔者的版本为0.8.0】 1.3 更新子模块【用于获取第三方库!很重要!】 二、CMake编译 2.1 设置路径 【source code: D:\Open3D\Open3D;build binaries: D:\Open3D】 【笔者设置CMAKE/CMAKE_INSTALL_PREFIX的路径为D:/Open.

累了就要打游戏 1万+

ZLMediaKit在Windows下启用WebRtc编译(64位)

准备软件 cmake-gui vs2017 已经编译好的windows版本openssl(下载地址) 当然,你完全可以自己按照openssl的官网教程自己编译windows版本的openssl libsrtp编译安装 首先,需要将下载好的openssl解压并添加到环境变量。如下图,将下图路径添加到环境变量 其次,下载libsrtp(下载地址) 下载后解压并新建build文件夹,如下图: 在合适位置新建文件夹放置install后的srtp文件,如"D:\develop20..

byna11sina11的博客 1万+

E - Help Hanzo(LightOJ 1197)

传送门 Pssword: nefu Description Amakusa, the evil spiritual leader has captured the beautiful princess Nakururu. The reason behind this is he had a little problem w...

weixin_33890499的博客 186

YOLOv11改进 | 检测头篇 | 利用AFPN辅助YOLOv11检测头进行特征融合识别(全网独家创新)

本文给大家带来的最新改进机制是利用AFPN(渐近特征金字塔网络)来优化检测头,AFPN的核心思想是通过引入一种渐近的特征融合策略,将底层、高层和顶层的特征逐渐整合到目标检测过程中。这种渐近融合方式有助于减小不同层次特征之间的语义差距,提高特征融合效果,使得检测模型能更好地适应不同层次的语义信息。本文在AFPN的结构基础上,为了适配YOLOv11改进AFPN结构,同时将AFPN融合到YOLOv11中(因为AFPN需要四个检测头,我们只有三个,下一篇文章我会出YOLOv11适配AFPN增加小目标检测头)

Snu77的博客 3750

LightOJ1197 Help Hanzo 区间筛

LightOJ1197 Help Hanzo 标签 区间筛法 前言 我的csdn和博客园是同步的,欢迎来访danzh-博客园~ 简明题意 求区间质数个数(区间长度<=1e6) 思路 区间[l,r]中的和数,质因子一定有一个<=sqrt( r)。因此提前筛出[1,sqrt( r)]中的质数,然后枚举这些质数的倍数就可以了。 注意事项 注意在区间中移动的指针应...

danzh 201

Statistics and Machine Learning Toolbox

Statistics and Machine Learning Toolbox(带书签),MATLAB统计学习工具

SAP B1中文培訓教材_SDK

公司内部培训资料,对开发工具 ,DIAPI, UIAPI,Add-ON有详细解说

Help Hanzo LightOJ - 1197 区间素数筛

问题: Amakusa, the evil spiritual leader has captured the beautiful princess Nakururu. The reason behind this is he had a little problem with Hanzo Hattori, the best ninja and the love of Nakururu. Aft...

HXX904的博客 374

数学建模模型总结

这是本人在两年内准备参加数学建模竞赛搜集到的模型资料,已经经过了本人的筛选和整理,希望能够对准备参加数学建模竞赛的学弟学妹们提供一些帮助!

LightOj 1197 Help Hanzo (区间筛法)

Amakusa, the evil spiritual leader has captured the beautiful princess Nakururu. The reason behind this is he had a little problem with Hanzo Hattori, the best ninja and the love of Nakururu. After he...

XYBDX的博客 324

假人有限元模型

假人模型,车辆碰撞假人有限元模型,适合做乘员安全的研究者利用

LightOJ 1197 - Help Hanzo (模拟筛素法区间筛素)

1197 - Help Hanzo   PDF (English) Statistics Forum Time Limit: 2 second(s) Memory Limit: 32 MB Amakusa, the evil spiritual leader has captured the

滴水穿石,慢慢积累,总会有成果 1053

M - Help Hanzo LightOJ - 1197 (区间筛法求素数)

Amakusa, the evil spiritual leader has captured the beautiful princess Nakururu. The reason behind this is he had a little problem with Hanzo Hattori, the best ninja and the love of Nakururu. After he...

短发 350

【区间筛法】 LightOJ 1197 Help Hanzo

题目地址:http://www.lightoj.com/volume_showproblem.php?problem=1197 这道题的题意大致是要我们从给定的范围内筛选出素数的个数,第一想法自然是欧拉筛法(线性筛)。 然而当我们看数据范围,1 ≤ a ≤ b 31,并不能愉快的玩耍,毕竟这个范围实在太大。 但是我们看到,b-a只有1e5的大小,因此我们可以在范围内用筛法找素数。具体

曜雨丶的博客 380

LightOJ 1197 - Help Hanzo (区间筛)

LightOJ 1197 - Help Hanzo (区间筛)

weixin_62802134的博客 784

【代码超详解】LightOJ 1197 Help Hanzo(区间质数筛法)

一、题目描述 二、算法分析说明与代码编写指导 对于求指定区间 [a, b] 的质数的题目,通常 a 和 b 都比较大,而 b - a 不太大。 采用埃氏筛或者欧拉筛的代码,一般都会同时给出前若干个质数。如果有 m 个不超过 n 的数要判断是否为质数,最坏情况下的时间复杂度为 π(n) 为不大于 n 正整数中的质数数量。 在本例中,可以代入最坏情况 m = 100001,n = 2^31,得数据...

COFACTOR 462

Help Hanzo LightOJ - 1197

Help Hanzo LightOJ - 1197 区间素数筛 const int LEN = 1e6+1; bool vis[LEN]; LL Prime[LEN]; int cnt = 1; void init(void) { int n = 70000; for(int i = 2; i &lt;= n; ++i) { if(!vis[i]) ...

海边拾贝,沧海一粟 245

LightOJ1197 - Help Hanzo(区间素数筛 + 模板)

题目链接:https://vjudge.net/problem/LightOJ-1197题目大意:给出a,ba,b求[a,b][a,b]内素数个数,保证b−a<100000b - a < 100000,1≤a≤b<2311\le a\le b<2^{31}。解题过程:这题有点可惜,没仔细想就去翻书了,挑战第二版 P121,当初这里看过了,以为只有一个埃氏筛法然后跳过了,有点可惜…题目分析:首先对于任

ACM_Fish的博客 1071

数论(筛区间质数) - Help Hanzo LightOJ - 1197

数论(筛区间质数) - Help Hanzo LightOJ - 1197 题意: 求区间[a,b]有多少个素数求区间[a,b]有多少个素数求区间[a,b]有多少个素数 Input 多组输入,第一行是t表示有t组数据,接下来每行一对a,b多组输入,第一行是t表示有t组数据,接下来每行一对a,b多组输入,第一行是t表示有t组数据,接下来每行一对a,b Output 输出"Case x:"后再输出答案输出"Case \ x:"后再输出答案输出"Case x:"后再输出答案 Sample In

njuptACMcxk的博客 283

数学-B Help Hanzo (LightOJ - 1197 )

暴力筛TLE直接开数组MLE#include &lt;stdio.h&gt; #include &lt;math.h&gt; #include &lt;string.h&gt; using namespace std; int vis[100010]; long long sushu[100010]; int shai[100010]; int main() { long long n...

Du_Ra_Ra_Ra的博客 374

Help Hanzo 求大区间素数个数

题目: Amakusa, the evil spiritual leader has captured the beautiful princess Nakururu. The reason behind this is he had a little problem with Hanzo Hattori, the best ninja and the love of Nakururu. Aft...

zhangjinlei321的博客 508
上一篇: 区间筛素数模板
下一篇: Trailing Zeroes (III) LightOJ - 1138(二分+阶乘性质)
Guuuuuu老师儿
博客等级 码龄9年 259粉丝 718原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值