UVA 1644 - Prime Gap

swl安装无法与服务器建立链接,如何解决? 🏆本文收录于《全栈Bug调优(实战版)》专栏,主要记录项目实战过程中所遇到的Bug或因后果及提供真实有效的解决方案,希望能够助你一臂之力,帮你早日登顶实现财富自由🚀;同时,欢迎大家关注&&收藏&&订阅!持续更新中,up!up!up!! 备注:部分问题/疑难杂症搜集于互联网。 阅读详情

求某一个数的 右边的素数 与 左边素数的 差。


必然素数打表。  然后再把 一个数的 左边的素数 及 右边的素数 打表。


就很好做了。


#include <cstdio>
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <string>
#include <map>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <cctype>
using namespace std;
#define ll long long
typedef unsigned long long ull;
#define maxn 1300000+100
#define INF 1<<30
int prime[maxn] = {0};
int left_[maxn] = {0},right_[maxn] = {0};
int init(){
    int m = sqrt(maxn);
    prime[1] = 1;
    vector <int> q;
    for(int i = 2; i <= m; i++){
        if(!prime[i]){
            for(int j = i*i; j <= maxn; j+=i){
                prime[j] = 1;
            }
        }
    }
    for(int i = 2; i <=maxn; i++){
        if(!prime[i])
            q.push_back(i);
    }
    int len = q.size();
    for(int num = 1; num < len; num++){
        for(int i = q[num]+1; i < q[num+1]; i++){
            left_[i] = q[num];
            right_[i] = q[num+1];
        }
    }
}
int main (){
    int n;init();
    while(scanf("%d",&n) && n){
        if(!prime[n])
            printf("0\n");
        else{
            printf("%d\n",right_[n] - left_[n]);
        }
    }
    return 0;
}


【系统分析师】写作框架:软件设计模式及其应用 本文围绕"软件设计模式及其应用"展开论述。首先介绍了近三年参与的某软件开发项目背景及个人承担的系统设计工作。其次系统阐述了设计模式的三大分类:创建型(如工厂方法、单例模式)、结构型(如适配器、装饰器模式)和行为型(如观察者、策略模式),重点分析了各类模式的特点和典型应用场景。最后结合项目实践,详细说明了采用的三种设计模式的具体实施过程及效果,包括提高代码复用性、降低耦合度等优势。文章还总结了项目经验,指出存在的不足及改进方向,强调合理运用设计模式对构建高质量软件系统的重要性。全文通过理论 阅读详情

相关推荐

光谱特征选择之模拟退火算法SA

光谱特征选择之模拟退火算法SA。

weixin_42621095的博客 901

习题10-4 素数间隔 UVa1644

1.题目描述:点击打开链接 2.解题思路:根据题意可知最大的素数在int范围内,可以先算出1299709以内的所有素数,随后二分查找n附近的素数的位置即可。 3.代码: #define _CRT_SECURE_NO_WARNINGS #include #include #include #include #include #include #include #include #includ

Skyline 1046

S32K3 MCAL配置 【MCU、PORT、DIO】

1、s32k3时钟源可由PLL, FXOSC, FIRC, SIRC, and SXOSC五种时钟源生成,可按照手册推荐配置。目标是在在S32K344板子上点亮红色LED灯,需要配置的有MCU、PORT、DIO模块。MCU最主要的是时钟配置,要翻看芯片手册,理解时钟树。1、通用配置中,没有什么特殊需求按照demo配置就好。1、配置MC_CGM mux 0 clocks时钟。1、外部晶振配置按照实际项目原理图进行配置。1、外部晶振配置,按照实际项目配置。1、PLL时钟按照手册进行配置。

weixin_43741076的博客 3248

UVA1644(素数间隔)。

打个表,挨个找就可以了。 1 #include <iostream> 2 #include <algorithm> 3 #include <cstring> 4 #include <cstdio> 5 #include <cstdlib> 6 #include <cmath> 7 ...

266

高效 DEM 拼接

通过以上步骤的系统实施,能够实现高效、准确的大型地理信息系统 DEM 数据拼接,满足复杂和大规模项目的应用需求。

llhllq2015的博客 1035

Android Qcom Display学习(十一)

该系列文章总目录链接与各部分简介:本章主要是基于MIPI Payload传输接口的学习,包括Generic和DCS的接口不同。底层都是基于去封装的,下面第一部分调用原生接口,第二部分分析高通是如何进行读写操作的。

Android驱动开发 3183

UVa 1644 - Prime Gap

数学题,筛法选素数,然后根据素数表再打表。

_____ 1414

STM32G4实战:用CubeMX+Keil五分钟搞定FreeRTOS多任务LED控制(避坑指南)

本文详细介绍了如何在STM32G4系列芯片上使用CubeMX和Keil快速配置FreeRTOS实现多任务LED控制,包括环境准备、时钟配置、任务创建及常见问题解决方案。重点解决了时钟源冲突等高频问题,并提供了优化建议和进阶应用示例,帮助开发者高效完成嵌入式开发任务。

joy55的博客 224

UVA1644 Prime Gap题解

题目大意 有多组数据,每组一个n,若n为0,程序结束。若n为质数,输出0.否则输出离它最近的两个质数(一个比n大,一个比n小)之差。(质数最大为 1299709,即抵十万个素数。) 分析 可先用筛法筛一筛,预先处理出质数,然后输入n,若n为质数,输出0,若不为,可从第2个质数往后扫,当出现第一个大于n的数时,即可将他减去上一个质数,即为答案。时间为50ms。 #include&lt;bi...

一个AFO的蒟蒻 507

【深度学习】肺结节分割项目实战二:分割肺实质

在后续训练模型的时候如果直接使用原始的肺部CT图像,其中的非肺区域会对训练造成干扰,因此我们需要提取分割肺实质。这一部分参考了kaggle上的教程。 从这张CT图像中可以看出扫描器以外的部分为黑色,背景和肺内部颜色较深,非肺组织和骨头颜色较浅。我们的目的是将肺部分割出来。由于肺部区域和其他部分对比明显,我们可以设置一个合适的阈值对图像中的区域进行隔离。 import argparse import os import numpy as np from medpy.filter.smoothing imp

weixin_42182906的博客 7242

把慢点掰开看:在 SAP HANA 中启用 SQL 优化耗时跟踪 SqlOptTime 的实战指南

摘要:SAP HANA 性能排查中,常出现SQL查询时快时慢的现象,表面看似执行问题,实则是编译阶段耗时过长。通过SQL优化跟踪工具SqlOptStep和SqlOptTime,可精准区分编译与执行时间。SqlOptStep展示优化树变化过程,而SqlOptTime则记录各阶段耗时,帮助定位问题根源。启用SqlOptTime需配置traceprofile,建议限定特定用户以减少系统负载。实际案例显示,报表响应慢常由计算视图编译(CeQo)导致,而非执行阶段问题。解决方案包括调整计算视图展开方式或优化基础视图结

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

UVA - 1644Prime Gap素数间隔

Prime Gap 欧拉筛法打素数表,同时用ans[]数组记录下两素数的间隔。 最终将v[],ans[]都遍历一遍,时间复杂度O(n); 核心代码: for(int k=p[np-1]+1;k<p[np];k++) { ans[k]= p[np]-p[np-1]; } #include<stdio.h> #include<iostream> #include&lt...

SongyangJi 557

《Linux GPU 驱动核心机制:面向图形与 AI 计算的 DRM 内存管理与任务调度》 目录

本文以缓冲区对象(BO)生命周期为主线,系统解析 Linux DRM 子系统中 GPU 驱动的核心机制。涵盖 GEM 与 TTM 内存管理、dma-buf/dma-fence 共享同步、GPU 调度与地址空间管理,结合 amdgpu、Xe 等驱动代码,深入剖析其设计动机与实现逻辑。旨在填补中文领域对 GPU 内核机制系统性讲解的空白,为图形与 AI 计算场景下的内存泄漏、同步死锁等疑难问题提供可追溯的分析路径。

图形/计算GPU的驱动与虚拟化技术分享园地 3738

Prime Gap UVA - 1644

问题 分析 水题,不过因为数据原因,直接从n的位置往前,往后搜索,更加快 #include <cstdio> #include <iostream> #include <cmath> using namespace std; const int maxn=1299709+10000; int n,vis[maxn],pre[maxn],post[maxn]; ...

zpf1998的博客 169

锂电池充电器电路设计 里面有电路

锂电池充电器电路设计 里面有电路 3.7V升压到5V电路设计。

蓝牙模块HM-10手册

蓝牙模块HM-10手册,该手册对蓝牙模块HM-10进行了详细的介绍和使用方法以及一些AT指令。

【uva1644】 素数间隔 Prime Gap [数学 质数筛]

UVA1644 素数间隔 Prime Gap 有多组数据,每组一个n,若n为0,程序结束。若n为质数,输出0.否则输出离它最近的两个质数(一个比n大,一个比n小)之差。(质数最大为 1299709,即抵十万个素数。) 真的hei水 非常水 超级无敌水 拿来背质数筛 线性筛法 -- 欧拉筛法 比普通的Eratosthenes筛法(复杂度为(O(nloglogn))效率要高些 为...

weixin_30258901的博客 393

深度学习工具包 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');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

uva 1644 Prime Gap 二分

点击打开链接 #include #include #include using namespace std; typedef long long ll; const int N=1e5+20; const ll M=1299709; vector p; ll n; bool check(int x) { for(int i=2;i*i<=x;i++) { if(x%i==0)

Masamiiiiii 525

visio安装包

Microsoft Office Visio 是一款专业的制图软件。利用经过更新的形状、协作工具和数据链接图表,创建专业级图表以简化复杂的信息。

UVA 1644 Prime Gap

The sequence of n - 1 consecutive composite numbers (positive integers that are not prime and not equal to 1) lying between two successive prime numbers p and p + n is called a prime gap of length n

qq_29055721的博客 360

UVA - 1644 Prime Gap

The sequence of n - 1 consecutive composite numbers (positive integers that are not prime and not equal to 1) lying between two successive prime numbers p and p + n is called a prime gapof length n 

爆米 812

UVa1644 Prime Gap

题意:给一个数n,输出它后一个素数和前一个素数的差,如果n是素数输出0。 思路:

A Cube Master 682

UVa1644 - Prime Gap

#include using namespace std; const unsigned maxn = 1300010; int p[maxn], n; bool np[maxn] = {true, true}; int main() { ios::sync_with_stdio(false); for(int i=2; i<maxn; i++){ if(!np[i

Dosth_Magic 822

UVA1644 - Prime Gap

筛选法 #include typedef unsigned long long llu; const llu M=1299710; const llu N=100000+10; int cnt=0; int a[M]; int b[N]; void sar(){ llu temp; a[0]=a[1]=1; for(llu i =2; i<M;i++){

RonggeRace的专栏 611

Prime Gap UVA - 1644 水题

The sequence of n − 1 consecutive composite numbers (positive integers that are not prime and notequal to 1) lying between two successive prime numbers p and p + n is called a prime gap of length n.Fo

qq_31674715的博客 605

UVA 1644 - Prime Gap(埃氏筛)

题目链接 https://cn.vjudge.net/problem/UVA-1644 【题意】 输入一个数字n(0 &lt; n &lt;= 1299709)求它后一个素数与前一个素数的差值,输入是素数时输出0. 【思路】 将输入范围内所有素数筛出来然后二分即可 #include&lt;bits/stdc++.h&gt; using namespace std; const in...

Change the world by program. 281

UVa 1644 - Prime Gap(筛法选素数)

筛法选素数。

ZmiL_ 580

UVA1644 素数间隔 Prime Gap

这个题就是质数的判定,然后用二分效率能高一些,首先看题目的范围,我们知道可以用质数筛,先求出来需要用的质数,当然还有一种方法是以输入的数为中心向两边扩展,感觉这样子也行但是没试,我们先预处理出来可能用到的质数,然后一开始我用的是线性的做法,看了别人的题解才想起来这里可以用二分把时间从线性优化到log,就是找第一个大于等于输入的质数,然后输出答案就行了,感觉自己还是菜了啊,一开始写的时候没有用二分。

m0_73035684的博客 226
上一篇: UVA 11526 - H(n)
下一篇: UVA 1637 - Double Patience
Shimmer_
博客等级 码龄12年 28粉丝 141原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值