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

保姆级教程:Unity编辑器汉化全流程(从下载到配置避坑指南) 本文提供Unity编辑器汉化的保姆级教程,涵盖从下载中文语言包到配置避坑的全流程。详细解析版本适配、文件系统交互及编辑器底层配置逻辑,帮助开发者高效完成汉化,解决常见报错问题,提升工作效率。 阅读详情

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;
}
使用 Simulink 和 Simscape Electrical 工具箱设计一个 Buck 转换器系统 Buck 转换器(降压转换器)是一种常用的 DC-DC 转换器,用于将较高的输入电压转换为较低的输出电压。为了评估其抗干扰能力,我们可以在模型中引入不同的干扰源,并观察系统的响应情况。电网电压波动:输入电压的变化。负载突变:负载电阻或电感的变化。电磁干扰:高频噪声或脉冲干扰。通过模拟这些干扰,我们可以分析系统的动态响应特性,并采取相应的措施来提高系统的抗干扰能力。 阅读详情

相关推荐

【电击防护篇】电击防护技术详解:从人体效应到接地系统全解析

本文系统讲解了电击防护的关键知识,包括电流对人体的影响(如30mA是心室颤动阈值)、人体电阻特性(700Ω-6100Ω)以及电气接触防护措施。重点分析了TT、TN和IT三大接地系统的结构特点与应用场景,强调TN-S系统最安全,IT系统供电连续性最佳。详细介绍了漏电保护器(RCD)的工作原理与选型指南,建议人身防护选用30mA高灵敏度RCD。文章通过对比表总结三大系统的安全性、成本及适用场景,为电气安全设计提供实用参考。

2301_81299416的博客 1773

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 365

Windows显卡TDR超时导致Unity崩溃?手把手教你修改注册表延长响应时间

本文详细解析了Windows显卡TDR超时导致Unity崩溃的问题,并提供了修改注册表延长响应时间的完整解决方案。通过调整TdrDelay和TdrDdiDelay键值,开发者可以有效避免D3D11设备丢失错误,提升Unity编辑器的稳定性。文章还包含显卡驱动优化、系统性能调优等实用技巧,帮助开发者彻底解决编辑器崩溃问题。

weixin_33737774的博客 654

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的博客 360

用Python爬取公众号历史所有文章,看这篇就够了

手把手教你爬取公众号历史所有文章

u010522887的专栏 1万+

Figure 03人形机器人与Helix端到端控制系统:具身智能突破深度解析

2026年5月,Figure AI的Figure 03人形机器人在一场震撼业界的直播中完成了长达200小时的连续全自动作业,分拣近25万个包裹,零故障。这一里程碑式的成就标志着人形机器人正式从「实验室展示」迈入「规模化商用」阶段。本文深入剖析Figure 03的核心技术——Helix端到端神经网络控制系统,包括System 0/1/2三层架构、视觉运动策略、全身协同控制等关键技术,并提供完整的Python/Go代码示例,帮助开发者理解具身智能的核心原理与实现路径。关键词。

shao.bing的专栏 1017

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

面向元数据的 SAP UI 中枢:namespace sap.ui.mdc 全景解析

如果把应用前端比作一条数据到交互的装配线,sap.ui.mdc 就是那条线的标准化工装:以 PropertyInfo 描述原料,以 Delegate 定义装配方法,以 p13n 与 VariantManagement 交付面向个体的最终产物;而 Condition Model、Operator 与 ValueHelp 则让输入与筛选的语义落地。与 OData V4 服务与 Fiori Elements 宏构件组合使用时,它能在保持一致体验的同时,给自由式开发者留下足够的可编排空间。

2007 年 ~ 2025 年,深耕 SAP 技术 18 年 248

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...

qq_43690454的博客 213

数字电路与逻辑设计实验二 组合逻辑电路

1.组合逻辑电路功能测试 (1)用 2 片 74LS00 组成图 2.1 所示逻辑电路。为便于接线和检查,在图中要注明 芯片编号及各引脚对应的编号。 (2)图中 A、B、C 接逻辑开关,Y1,Y2 接发光管电平显示。 (3)按表 2.3 要求,改变 A、B、C 输入的状态,填表并写出 Y1,Y2 的逻辑表达式。 (4)将运算结果与实验结果进行比较。 2.测试用异或门(74LS86)和与非门组成的半加器的逻辑功能。 根据半加器的逻辑表达式可知,半加 器 Y 是 A、B 的异或,而进位 Z 是 A

欢迎交流学习心得 1282

DeepSeek+即梦:AI视频创作从0到1全突破

本文为 DeepSeek 与即梦生成视频全攻略,从前期注册登录、熟悉工具界面及硬件网络准备入手,助读者开启 AI 视频创作。详细阐述利用 DeepSeek 构思脚本、即梦实现画面生成与静态图转动态视频的方法,包括提示词编写、参数调整等技巧。同时介绍后期合成音画、添加字幕特效及多平台适配要点,结合实战案例解析全流程。还分享进阶提示词优化、版权注意等避坑指南,为创作者提供从 0 到 1 的 AI 视频创作完整解决方案。

邓邓子的博客 8154

lightoj 1197 奇怪筛法

奇怪筛法 Time Limit:2000MS     Memory Limit:32768KB     64bit IO Format:%lld & %llu Submit Status Description Amakusa, the evil spiritual leader has captured the beautiful princess Nakururu. T

wust_ZJX的专栏 1007

ET2012新版免狗免安装绿色软件

ET2012新版免狗免安祖昂绿色软件。,新界面,新视觉,

LightOJ1197 Help Hanzo 区间筛

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

danzh 202

RU DOS版、EFI版32bit/64bit BIOS常用工具

DOS版、EFI版的RU工具,可用来查看IO、MEM、PCI、SMBIOS等资源。亲测在EFI SHELL下可用。

汉书HE8,好用的汇编代码编写工具

汉书HE8,好用的汇编代码编写工具早期编写汇编代码所用功能强大

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的博客 377

IDEA的使用指南

IDEA基于java的使用手册,可以最快速的上手,在使用中不断的丰富自己的使用技巧.

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的博客 326

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...

短发 351

【区间筛法】 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的博客 786

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

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

COFACTOR 466

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的博客 1075

数论(筛区间质数) - 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的博客 285

数学-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的博客 376

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的博客 188
上一篇: 区间筛素数模板
下一篇: 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、付费专栏及课程。

余额充值
⌂ 换网址