Poj,2689/Runtime error/求大神解答/新手

图雀社区 图雀社区 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <stack>
#include <set>
#include <cstdlib>
#include <algorithm>
using namespace std;
const int maxn = 1000;
long long L,U;
bool vis[maxn];

vector<bool> isPrime(maxn,true);
vector<int> primes(maxn);
void prime(){
memset(vis,true,sizeof(vis));
int pos=1;
primes[0]=2,vis[2]=false;
for(int i=3;i<maxn;i+=2){
if(isPrime[i]){
for(int j=i*i;j<maxn;j+=i)
{
isPrime[j]=false;
}
primes[pos++]=i;
vis[i]=false;
}
}
}

void prime2(){
int ans=0;
int ant=0;
int num1[maxn],k=0,flag=0,m,n,q,p;
memset(num1,0,sizeof(num1));
while(L<=U){
if(!vis[L])
num1[k++]=L;
L++;
}
if(k<=1)
{
printf("There are no adjacent primes.\n");
}
else{
ans=num1[1]-num1[0];
ant=num1[1]-num1[0];
m=num1[0];n=num1[1];p=num1[0];q=num1[1];
for(int i=2;i<k;i++){
int temple=num1[i]-num1[i-1];
if(temple>ant)
{
ant=temple;
m=num1[i-1];
n=num1[i];
}
if(temple<ans)
{
ans=temple;
p=num1[i-1];
q=num1[i];
}
}
printf("%d,%d are closest, %d,%d are most distant.\n",p,q,m,n);
}
}
int main(){
prime();
while(~scanf("%lld %lld",&L,&U))
{
prime2();
}
return 0;
}
...全文

相关推荐

POJ经典基础题解题思路汇总:从输入输出到逆序数排序

在线评测系统(OJ)是编程学习者验证代码正确性、提升算法能力的重要平台。不同于商业刷题网站,传统OJ如北大POJ,以其严谨的输入输出规范和朴素的题目风格,成为ACM竞赛与考研机试的经典训练场。理解OJ的运行原理,掌握多组数据读入、边界条件判断、浮点精度处理等基础技巧,是高效刷题的前提。算法基本功方面,枚举、模拟、字符串处理与稳定排序是入门阶段的四大核心模型,几乎覆盖了大多数简单题与中等题。这些知识不仅适用于竞赛场景,也对日常工程开发中的逻辑严谨性训练大有裨益。本文基于实际刷题经验,系统梳理POJ前几十道代表

章华燕

fengmian123

fengmian123

CiYuanShuos

QYR-18900-2026-2032全球与中国智能旋转导向钻井系统市场现状及未来发展趋势 Sample-shijunzhong.docx

QYR-18900-2026-2032全球与中国智能旋转导向钻井系统市场现状及未来发展趋势 Sample-shijunzhong.docx

qyresearch报告

XERJ 是一款受到社区信赖的本地 AI 搜索引擎

XERJ 是一款受到社区信赖的本地 AI 搜索引擎,能自动为任意文件夹建立索引,让编程智能体直接检索所需代码,省去逐个读取文件消耗的 token。它的主要用途是参考现有实现来写代码(reference coding):接到任务后,智能体下载与任务相关的开源仓库,建立索引,再查阅这些项目的解决方法。 在一项对照研究中,这种做法让智能体的输出 token 用量降至原来的约 1/2.7,同时保持 16/16 的任务完成率(案例研究)。用户在日常开发中报告的用量约为原来的 1/5(使用反馈)。有了可检索的参考实现,较小、较便宜的模型也可能胜过只凭记忆工作的昂贵模型,减少反复修改的次数。把下面这段提示词交给智能体即可开始

yiersansiwu123d

DocRes.Vulkan.WinForms.VS2022-Source-r1.1-20261016-102846-206.zip

DocRes.Vulkan.WinForms.VS2022-Source-r1.1-20261016-102846-206.zip 博客地址:https://blog.csdn.net/lw112190/article/details/168119884

天天代码码天天
评论 1
收藏 已收藏
分享
返回顶部
图雀社区
Linux/Unix社区 18,828 成员 11,489 内容