UVa1210 Sum of Consecutive Prime Numbers

从混乱到清晰:用QJsonObject重构你的Qt网络API数据解析层(避坑指南) 本文详细介绍了如何使用QJsonObject重构Qt网络API数据解析层,避免常见的JSON解析陷阱。通过安全解析模式、数据绑定和性能优化技巧,帮助开发者构建高效、健壮的解析逻辑,提升代码可维护性和可读性。特别适用于处理复杂嵌套的JSON响应数据场景。 阅读详情

        题意:求一个数能表示为几组连续素数相加的形式。如41=2+3+5+7+11+13=11+13+17=41,结果就是3。

        思路:筛法素数打表,暴力枚举连续素数的起点和终点统计。


#include <iostream>  
#include <stdio.h>  
#include <cmath>  
#include <algorithm>  
#include <iomanip>  
#include <cstdlib>  
#include <string>  
#include <memory.h>  
#include <vector>  
#include <queue>  
#include <stack>  
#include <map>
#include <set>
#include <ctype.h>  
#include<time.h>
#define INF 1000000

using namespace std;

bool tab[10010];
int primes[2000];
int ans[10010];

int main(){
	for(int i=0;i<10010;i++)tab[i]=1;
	tab[0]=tab[1]=0;
	for(int i=2;i<=5000;i++){
		for(int j=i*i;j<=10000;j+=i){
			tab[j]=0;
		}
	}
	int count=1;
	primes[1]=2;
	for(int i=3;i<=10000;i+=2){
		if(tab[i])primes[++count]=i;
	}
	
	memset(ans,0,sizeof(ans));
	for(int i=1;i<=count;i++){
		int tmp=0;
		for(int j=i;j<=count;j++){
			tmp+=primes[j];
			if(tmp<=10000)ans[tmp]++;
		}
	}
	
	int n;
	while(cin>>n){
		if(!n)break;
		cout<<ans[n]<<endl;
	}
	
	return 0;
}


2025年三级等保新规实战:从零开始搭建企业安全防护体系(附完整配置清单) 本文详细解析2025年三级等保新规的核心变化,提供从零开始搭建企业安全防护体系的实战指南。重点介绍动态防护能力、实战化攻防验证和全链路数据保护等关键要求,并附完整配置清单,帮助企业高效合规。 阅读详情

相关推荐

Zemax物理光学实战:3分钟搞定高斯光束传播模拟(附菲涅尔局部分析技巧)

本文详细介绍了在Zemax中进行高斯光束传播模拟与菲涅尔局部分析的实战技巧。通过3分钟快速设置指南和参数解析,帮助光学工程师准确模拟激光光束特性,避免常见误区。特别分享了菲涅尔局部分析的关键技巧和传播参数优化策略,提升光学系统设计的精度与效率。

lambda的博客 804

UVA 1210 Sum of Consecutive Prime Numbers(数论)

UVA - 1210 Sum of Consecutive Prime Numbers Time Limit: 3000MS   Memory Limit: Unknown   64bit IO Format: %lld & %llu Submit Status Description Some positive integ

u013268685的专栏(有一种幸福叫AC,有一种期待叫AK) 1852

ADS 使用教程(十八)Encrypting Designs using RFIP Encoder in ADS

在这一节,我们使用RFIP Encoder进行设计加密,这是一种保护知识产权和敏感设计数据的重要方法。RFIP Encoder提供了一种安全的方式来加密设计文件,确保只有授权人员能够访问和使用这些文件。

Dirge19的博客 1169

【UVA】1210 - Sum of Consecutive Prime Numbers

普通的求区间连续和的问题,一开始因为是区间移动,但是怕UVA数据太严,直接打表,后来发现自己的担心是多余的。 14044972 1210 Sum of Consecutive Prime Numbers Accepted C++ 0.049 2014-08-15 10:30:11 打表的话效率可能不是很高. AC代码:

花月阁 1286

SiamRPN++实战:如何用深度孪生网络提升无人机目标跟踪精度(附代码)

本文深入探讨了如何利用SiamRPN++深度孪生网络构建适用于无人机平台的高精度、轻量化单目标跟踪系统。文章详细解析了其兼顾精度与效率的核心原理,并提供了从PyTorch模型轻量化、骨干网络替换到TensorRT部署及应对遮挡、光照突变等实际挑战的完整工程实践指南与代码示例。

weixin_29047545的博客 370

解决UNITE数据库注释高unassigned率:手把手教你训练专属真菌分类器(含预训练模型分享)

本文针对使用UNITE数据库进行真菌ITS序列注释时出现的高未分配率问题,提供了详细的实战解决方案。通过对比vsearch直接注释与Naive Bayes分类器的原理差异,文章手把手指导读者在QIIME 2环境中训练专属分类器,包括数据准备、模型训练、参数优化及效果验证,并分享了预训练模型,旨在显著提升真菌群落分析的注释准确性和数据利用率。

weixin_29214199的博客 338

UVA1210 连续素数之和 Sum of Consecutive Prime Numbers

UVA1210 连续素数之和 Sum of Consecutive Prime Numbers扫出 扫出1~10000内的所有素数,记录素数前缀和。 然后暴力O(n^2)。 还有个思路是用队列,一直往上加,不满足出队,O(n)就可以 1 #include <bits/stdc++.h> 2 using namespace std; 3 typedef l...

dieche3140的博客 367

NRF52832串口通信避坑指南:从SDK配置到硬件流控(RTS/CTS)实战

本文详细介绍了NRF52832串口通信的实战指南,从SDK配置到硬件流控(RTS/CTS)的完整实现。通过分析UARTE模块特性、解决SDK版本差异问题、正确配置硬件引脚以及实现稳定通信的代码示例,帮助开发者避开常见陷阱,确保高效可靠的串口通信。特别强调了硬件流控在高速通信中的重要性及其实践方法。

weixin_33739646的博客 282

Sum of Consecutive Prime Numbers UVA - 1210

求素数前缀和,把输入的数字n当成连续的素数之和,必定会有sum1-sum2 = n,也就是说sum1和sum2都存在于前缀和数组中,统计sum1或者sum2的个数 #include #include #include #include using namespace std; vector primes; const int MAXM = 1799800; bool is_prime[MAX

LutherLau 264

【5】GD32H7xx CAN发送及FIFO接收

GD32H7xx CAN收发调试记录,包含源码

madao1234的博客 1813

【AI大模型应用开发】3.2 RAG实战 - RAG应用+UI实现加载本地文件并对话

前面我们实现了RAG基本流程,今天我们在此基础上给它加个UI界面,在浏览器打开,实现上传本地文件、解析,并用大模型实现与该文档的对话。也就是一个阉割版demo版的ChatPDF或知识库对话系统。

同学小张的博客 3054

Sum of Consecutive Prime Numbers UVA - 1210 前缀和 线性筛法

问题 分析 #include <cstdio> #include <iostream> #include <algorithm> #include <cstring> #include <cmath> #include <vector> using namespace std; const int maxn=10005,Inf...

zpf1998的博客 178

Statistics and Machine Learning Toolbox

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

题解 UVA1210 【Sum of Consecutive Prime Numbers】

题目链接:Link Solution 由于素数都是正数,因此可以把素数预处理成一个队列,每次都尽量往上加。这样就可以用O(n)的时间算出方案数。 #include<cstdio> inline bool isp(int a) { for(int i=2;i*i<=a;i++) if(a%i==0) return false; return...

donglaishi1835的博客 176

精雕软件(JDpaint) 5.5 绿色版

精雕软件(JDpaint) 5.5 绿色版精雕软件(JDpaint) 5.5 绿色版精雕软件(JDpaint) 5.5 绿色版

IEM模型,地表粗糙度模拟

利用微波反演土壤水分时候,利用IEM模型可以实现对随机地表的模拟

UVa 1210 - Sum of Consecutive Prime Numbers

題目:計算連續素數的結合為n的組合有多少種。 分析:數論,數據結構。先打好素數表,然後順序掃描即可,類似維護一個隊列。 說明:╮(╯▽╰)╭。 #include #include int visit[10010]; int prime[10010]; int main() { memset(visit, 0, sizeof(visit)); int count = 0; for

小白菜又菜 2314

STM32F407中文手册

STM32f407中文手册 本参考手册面向应用开发人员,提供有关使用 STM32F405xx/07xx、STM32F415xx/17xx、 STM32F42xxx 和 STM32F43xxx 微控制器存储器与外设的完整信息。STM32F405xx/07xx、STM32F415xx/17xx、STM32F42xxx 和 STM32F43xxx 构成一个微 控制器系列,各产品具有不同的存储器大小、封装和外设。有关订购信息以及器件的机械与电气特性,请参见数据手册。有关 ARM Cortex™-M4F 内核的信息,请参见《Cortex™-M4F 技术参考手册》。

Uva-1210 Sum of Consecutive Prime Numbers

题目链接:Sum of Consecutive Prime Numbers 题目大意:输入一个数,求有多少种连续的素数和可以组成这个数。 解题思路:用筛法对素数打个表,然后用尺取法就行了。代码如下:#include <map> #include <set> #include <cmath> #include <queue> #include <stack> #include <cstdio> #

Minakami_Yuki的博客 806

UVA 1210 Sum of Consecutive Prime Numbers(素数打表)

题意:给定一个整数n, 问有多少个若干个连续的素数的和为n。 解题思路:打出MAX_N以内的素数表, 枚举即可。 Some positive integers can be represented by a sum of one or more consecutive prime numbers. How many such representations does a given

MingShen 887

UVa1210 - Sum of Consecutive Prime Numbers

#include const int maxn=10010; int isp[1250],pre_p,sum[1250]; bool np[maxn]={true,true}; void prepare(){ for(int i=2;i<maxn;++i){ if(!np[i]) isp[pre_p++]=i; for(int j=0

Dosth_Magic 759

UVA 1210 Sum of Consecutive Prime Numbers

https://vjudge.net/problem/UVA-1210 统计质数前缀和,枚举左右端点,这一段的区间和+1 #include<cstdio> #define N 10001 using namespace std; int cnt,p[N],sum[N],ans[N]; bool v[N]; int main() { for(in...

weixin_30536513的博客 71

UVA1210 Sum of Consecutive Prime Numbers题解

题目大意 有多组数据,每组一个n,以0结尾,若n=0,程序结束,求有多少种方法将n写成连续素数之和(n&lt;=10000)。 分析 可预先将1到10000的素数和其前缀和处理出来,记为数组sum,在进行循环,判断是否有i,j,使得sum[i]-sum[j]=n,若有,则ans++。最后输出ans,时间为80ms。 #include&lt;bits/stdc++.h&gt; using...

一个AFO的蒟蒻 262

Sum of Consecutive Prime Numbers UVA - 1210 连续素数之和

紫书p343 素数打表,再求前缀和,最后通过两重循环,通过前缀和快速求出区间值,找到满足的数就答案+1 #include #include #include #include #include #include #include #include #include #include using namespace std; const int INF=1e9+10; ty

熟睡的哲学家的博客 384

Sum of Consecutive Prime Numbers - UVa 1210 水题

Some positive integers can be represented by a sum of one or more consecutive prime numbers. How many such representations does a given positive integer have? For example, the integer 53 has two repre

提比的强行AC 930

UVA - 1210 - Sum of Consecutive Prime Numbers

找到上限,直接暴力枚举即可 #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define Memset(x) memset(x,

TianTengtt的博客 621
上一篇: UVa1213 Sum of Different Primes
下一篇: UVa10539 Almost Prime Numbers
squee_spoon
博客等级 码龄14年 61粉丝 455原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值