#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)
s_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;
}
相关推荐
CosyVoice 本地部署详细教程 手把手小白教程
本文提供了详细的CosyVoice本地部署教程,强调了避免中文名称和空格的重要性,并列出了必要的软件安装步骤,包括CUDA、cuDNN、Git和Miniconda。教程涵盖了从检查CUDA版本到下载模型和运行模型的全过程,确保用户能够顺利部署并使用CosyVoice。
[模板] 区间筛素数
原理:一个数的倍数肯定不是素数 若给定子区间[fst, lst] 则必有区间内任意数最大的因子是sqrt(lst); 因此只需要将2 - sqrt(lst)中的所有质数的倍数从区间[fst, lst]中划掉即可 剩下的就是区间内的素数 注意两个情况 1. 第一次筛出的素数就在区间里 要特判 2. 将区间[fst, lst]映射入[0, lst - fst] 3.bitset优...
自学PCB思路 | PCB设计零基础入门-小白适用(附详细入门经验分享)
本人大一在实践课上就听说PCB,被虎的一楞一楞的,不过现在回看,发现其实并没有相信的那么难!想着把自己这一路摸索的学习路线分享一下,当时我是一边摸索一边上手,一把鼻涕一把泪的过来的。如果你想搞硬件或者需要搞硬件,下面是我的入门学习过程,希望可以帮到你。目录前言选择一款设计软件好的入门课程掌握抄板元件采购焊板子烙铁头热风枪自己半设计明确设计需求全设计最后我并非什么大佬,也没法自己去教大家如何画板。
区间素数筛模板
接口:qujiansushu(左端点,右端点)闭区间,返回区间中素数的个数 bool f[100005]; int qujiansushu(long long a,long long b) { int num = 0; int l = b - a;//将a到b转化为从0到b - a for(int i = 0 ; i < primeCount && prime[i
I2C总线原理及总线信号的实现
I2C总线是一种多主机总线,连接IIC总线上的器件分为主机和从机,主机有权发起和结束一次通信,而从机只能被主机呼叫;当总线上有多个主机同时启用总线时,I2C也具备冲突检测和仲裁的功能来防止错误产生;每个连接到IIC总线上的器件都有一个唯一的地址(7bit),且每个器件都可以作为主机也可以作为从机(同一时刻只能有一个主机),总线上的器件增加和删除不影响其他器件正常工作;I2C总线在通信时总线上发送数据的器件为发送器,接收数据的器件为接收器;主要用于近距离(抗干扰能力稍弱),低速的芯片之间的通信(传输视频,带宽
家用电器维修必备:手把手教你用双向可控硅改造单相电机调速(附电路图)
本文提供了一份详细的家用电器维修指南,手把手教你如何利用双向可控硅为核心元件,为单相交流电机(如风扇、排气扇)实现平滑的无级调速改造。内容涵盖核心原理、安全须知、元件选型(如BT136、DB3)、电路图解析、分步搭建教程以及常见故障排查方法,旨在帮助维修爱好者和DIY用户安全、成功地完成这一实用且富有成就感的项目。
区间素数筛法
题目描述 筛法是一种简单检定素数的算法。据说是古希腊的埃拉托斯特尼(Eratosthenes,约公元前274~194年)发明的,又称埃拉托斯特尼筛法(sieve of Eratosthenes)。 以上是百度百科的定义。不得不佩服古希腊人的智慧。今天希望你在古人智慧的基础上解决问题:给定正整数a和b,请问区间[a,b)内有多少个素数。 输入 有多组样例,每组样例有2个正整数a,b(a&...
SAP-ABAP:字符与数值类型转换详细指南
SAP-ABAP:字符与数值类型转换详细指南
筛选区间素数模板(poj2689)
#define _CRT_SECURE_NO_WARNINGS #include <iostream> #include <cstdio> #include <algorithm> #include <cstring> using namespace std; const int maxn = 100000 + 10; int prim...
复数值神经网络可能是深度学习的未来
复数这种东西,在人的头脑中似乎抽象、似乎复杂,然而,对于计算机来说,一点也不抽象,不复杂,那么,将复数概念推广到神经网络会是什么结果呢?本篇介绍国外的一些同行的尝试实践,请我们注意观察他们的进展。
初识数据之特征选择
【代码】初识数据之特征选择。
POJ - 2689 区间筛素数(模板)
题目链接 题意 给定区间[l, r],长度小于1e6,l和r小于1e9,问这个区间中相邻两个素数差值的最大值和最小值。如果只有一个素数或者没有素数则输出There are no adjacent primes. 思路 模板题 因为每个合数x都有一个小于x\sqrt{x}x的因子,所以只要筛出[2,r][2, \sqrt{r}][2,r]之间的素数,然后枚举素数p,把这个区间中p的倍数全部筛掉即...
llama-factory微调qwen2.5-vl
使用llama-factory完成qwen2.5-vl微调
poj2689(素数区间筛法模板)
题目链接: http://poj.org/problem?id=2689 题意: 给出一个区间 [l, r] 求其中相邻的距离最近和最远的素数对 . 其中 1 <= l < r <= 2,147,483,647, r - l <= 1e6 . 思路: 素数区间筛 要找到 [l, r] 中相邻最近和最远的素数对肯定是需要找出 [l, r] 内所有素数 . ...
深度学习工具包 DeepLearningToolbox
深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[](https://bitdeli.com/free "Bitdeli Badge")
锂电池充电器电路设计 里面有电路
锂电池充电器电路设计 里面有电路 3.7V升压到5V电路设计。
[模板][洛谷P1835]素数密度(区间筛)
题目←每个数n的最小质因子一定不超过n√\sqrt{n} 预处理出m−−√\sqrt{m}内的素数表,删去每个素数在n-m区间内所有倍数,剩下的一定全为素数 del数组采用下标偏移,i实际表示数n+i是否已被删去 del数组大小为0~m-n#include<iostream> #include<cstdio> #include<algorithm> #include<cmath> #defin
NTscan扫描工具
ntscan是一个扫描器,可以扫描没有密码和弱密码的共享,先到配置文件中填写猜测的用户名和密码,扫描过程中右侧出现的是扫描日志。
POJ - 2689 Prime Distance(素数区间筛模板)
题目链接:点击查看 题目大意:给出一段闭区间[l,r],求区间内相邻距离最大的素数对和相邻距离最小的素数对,题目保证r-l<=1e6,1<=l<=r<= 题目分析:因为我们要求区间[l,r]内的最近和最远素数对,肯定要求出这段区间内的所有素数,l和r最大都能到1e9,并且其区间也到了1e6,暴力打表然后暴力遍历肯定是不行的,我们可以换一个思路,先在sqrt(1e9)的范...
Devexpress16.2.6破解工具
Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具
Help Hanzo LightOJ - 1197(区间筛素数模板题)
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...
素数筛
新手常用的素数筛总结及模板套用 在新手的比赛中,我们经常遇到关于素数的问题,而对于筛选他们的方式和每种筛法的承载量便值得探讨,作为菜鸡的我便举了以下几种筛法和可以直接套用的模板(1,我把筛法都整理成了自定义函数,便于大家直接套用;2,为避免数组爆炸,我将其设定为了全局变量)。 一 暴力筛 [优]暴力筛是最普通的筛,其无脑的循环筛选最让人容易上手。 [劣]经过测验,它的范围大约只有1~1e6,不能满足许多题目的要求;而且,较慢的筛选速度也很容易TLE。 #include<bits/stdc++.h&g
蒟蒻复习之—–数学
//以下是我的一些模板的整理 //只有板子,没有原理素数1.素数判定O(根号n)bool prime(int x) { if(x == 0 || x == 1) return false; for(int i = 2; i * i <= x; i++) { if(x % i == 0) return false; } return true; }2.
筛表合集(素数筛 欧拉函数筛 莫比乌斯函数筛)
【目录】 一、素数筛 1.素数判断 2.素数普通筛 3.素数线性筛 4.素数区间筛 二、欧拉函数筛 三、莫比乌斯函数筛 【素数筛】 1.直接判定质数 bool judgePrime( int num ) { if(num < 2 ) return 0; int tmp =sqrt( num ); for(int i= ...
区间筛法找素数
区间筛法用于快速筛出a到b区间的全部素数,b-a
区间素数筛选 poj2689
0.0
素数筛模板
快速幂模板 代码如下: #include <iostream> #include <cstring> using namespace std; #define N 10000 bool a[N]; int b[N], n; void prime () { n = 0; memset(a, 0, sizeof(a)); for(int i = 2; i <...
素数筛选及区间素数
埃氏筛法 算法复杂度O( n*log(log n) ) 原理:从2开始,每第一次出现且之前没有它的因数出现就一定是素数,然后再把它的所有倍数设为true bool isprime[maxn]; //maxn即需要求多少范围里的素数,maxn最大为2e^7 int prime[N]; //根据maxn的大小调节,该数组储存了maxn范围内的所有素数 int num; void Prime(){ ...
找素数
Description 给定区间[L, R] , 请计算区间中素数的个数。 Input 两个数L和R。 Output 一行,区间中素数的个数。 Sample Input 1 2 11 Sample Output 1 5 Hint HINT:时间限制:1.0s 内存限制:256.0MB 2 <= L <= R <= 2147483647 R-L <= 1000000 思路: 使用埃式筛法,筛出 [2,sqrt(R)] 中的素数,(因为一个
2万+



被折叠的 条评论
为什么被折叠?



