第六届蓝桥杯校内选拔赛C/C++高职组解题(2)

调和级数详解 调和级数详解,轻松学会调和级数计算。 阅读详情


1/1 + 1/2 + 1/3 + 1/4 + ... 在数学上称为调和级数。


它是发散的,也就是说,只要加上足够多的项,就可以得到任意大的数字。


但是,它发散的很慢:


前1项和达到 1.0
前4项和才超过 2.0
前83项的和才超过 5.0


那么,请你计算一下,要加多少项,才能使得和达到或超过 15.0 呢?


请填写这个整数。


注意:只需要填写一个整数,不要填写任何多余的内容。比如说明文字。




答案
1835421


代码

#include <iostream>
#include <cmath>
#include <string>
#include <windows.h>
#include <stack>
#include <vector>
#include <iomanip> 
#include <stack> 
#include <set>
#include <map>
#include <cstdio>
using namespace std;
#define N 8
int main()
{
	double sum=0;
	int k=0;
	while(sum<15)
	{
		k++;
		sum+=(double)1/(double)k;
	}
	cout<<k;
	return 0;
}




调和级数(筛法原理应用) for (int i = 1; i <= n;i++){ for (int j = 1; j <= n / i;j++){ //do(i,j,i*j) } } 以上代码可以 在 nlogn 的复杂度内,处理出 1~n 所有的数,且包含其约数信息 题1: 传送门 tip: 1<=ai<=1e6 int num[N]; signed main(){ int n; scanf("%d", &amp 阅读详情

相关推荐

Python:实现“调和级数“算法——让你了解更多数学算法

在本篇文章中,我们将探讨调和级数的性质,并提供Python语言的代码实现。调和级数是一个发散的级数,也就是说,对于任何正整数n,1+1/2+1/3+…这个级数的性质非常有趣,因为在实际应用中,调和级数经常出现在各种物理、工程、经济等方面的问题中。通过本篇文章的学习,我们了解了调和级数的性质,并学会了使用Python语言来实现这个算法。当然,这只是数学算法中的冰山一角,还有许多其他有趣的算法等待我们去探索。接下来,我们将给出Python语言的调和级数的实现代码,代码中的参数n表示要计算的级数的项数。

BUG?不存在的! 715

第一章:绪论

第一章:绪论 大O记号 T(n) = O(f(n))等价于存在c>0,当n达到一定值之后,有T(n) < c * f(n); 通俗而言,O(f(n))表示f(n)是T(n)的上界。 大O记号的两个特点: 其一,常系数可以忽略。即O(c*f(n)) = O(f(n)). 其二,低次项可忽略。比如O(n^2 + logn + n! + n^n) = O(n^n)。 其他记号:...

昂昂累世士的博客 2512

Dify + mem0插件实战:如何让AI记住你的饮食习惯(附完整代码)

本文通过Dify平台与mem0插件实战,详细演示了如何为AI助手构建长期记忆系统,使其能记住并理解用户的复杂饮食习惯(如过敏源、饮食偏好)。文章提供了完整的工作流配置与Python代码示例,帮助开发者实现跨会话的个性化饮食建议,解决AI对话中的“健忘”问题。

lg888的博客 1101

调和级数相关证明

调和级数1+12+13+⋯+1n−1+1n≈log(n) 1+\frac12+\frac13+\cdots+\frac1{n-1}+\frac1n\approx \log(n)

5935

免费 AIS船舶轨迹预测 数据集 分享 (可用于长周期轨迹预测)

论文中使用的数据由提供。有关预处理步骤的详细信息,请参阅。

qq_43747519的博客 1万+

基于单片机负载控制的无人机电气设备监测系统设计

为深入分析无人机电气设备的电子负载性能,实现对传输电子量的合理性监管与控制,设计基于单片机负载控制的无人机电气设备监测系统;利用电气信号发生电路,构建负载网络控制器与以太网模块运行所需的电气设备负载环境,借助PCB监控板建立PLC扩展负载模块与核心监控主机之间的物理连接关系,实现无人机电气设备监测系统的硬件执行环境搭建;在此基础上,通过STM32型单片机移植协议,确定无人机电气设备通信主机的现有组态形式,联合已设定的监控任务有线级条件,实现监测系统的软件执行环境搭建,完成基于单片机负载控制的无人机电气设备监

weixin_45905610的博客 1302

第六届蓝桥杯校内选拔赛C/C++高职组解题(6)

形如:1/a 的分数称为单位分数。 可以把1分解为若干个互不相同的单位分数之和。 例如: 1 = 1/2 + 1/3 + 1/9 + 1/18 1 = 1/2 + 1/3 + 1/10 + 1/15 1 = 1/3 + 1/5 + 1/7 + 1/9 + 1/11 + 1/15 + 1/35 + 1/45 + 1/231 等等,类似这样的分解无穷无尽。 我们增加一个约

qq120267583的专栏 1038

工业安全生产 AI 视频分析与隐患识别平台技术方案

工业安全生产 AI 视频分析与隐患识别平台技术方案2026 年是我国安全生产专项整治三年行动巩固提升的收官之年,也是 "十四五" 安全生产规划全面落地的关键节点。国家应急管理部最新发布的《"工业互联网 + 安全生产" 行动计划(2026-2028 年)》明确提出,到 2028 年底,全国规模以上工业企业安全生产数字化覆盖率要达到 95% 以上,高危行业企业要 100% 建成智能化安全监测预警系统。国务院安委会印发的《关于进一步加强安全生产隐患排查治理体系建设的指导意见》要求,所有化工、矿山、建筑施工等高危行

随读手记 438

第六届蓝桥杯校内选拔赛C/C++高职组解题(7)

你一定听说过“数独”游戏。 如【图1.png】,玩家需要根据9×9盘面上的已知数字,推理出所有剩余空格的数字,并满足每一行、每一列、每一个同色九宫内的数字均含1-9,不重复。 数独的答案都是唯一的,所以,多个解也称为无解。 本图的数字据说是芬兰数学家花了3个月的时间设计出来的较难的题目。但对会使用计算机编程的你来说,恐怕易如反掌了。 本题的要求就是输入数独题目,程序

qq120267583的专栏 1110

知识图谱中的 Ontology(本体论)

本文的部分图片和内容来自中国科学院自动化研究所刘康老师的课件 Ontology(本体论) Ontology 是(特定领域)信息组织的一种形式,是领域知识规范的抽象和描述,是表达、共享、重用知识的方法。 Ontology 是知识体系构建的关键技术,知识图谱是一种人工智能技术,它的关键在于让计算机能够处理人类的知识。然而,人类脑海中的知识通常是直觉性的,我们无法将这种直觉性的知识直接输入给计算机,On...

P01son的博客 2万+

泰山派RK3576开发板部署Qwen3-VL-4B多模态模型实战指南:从模型转换到板端推理全流程

本文提供了在泰山派RK3576开发板上部署阿里Qwen3-VL-4B多模态模型的完整实战指南。详细介绍了从环境准备、模型转换(包括视觉模型转换为.rknn格式和语言模型转换为.rkllm格式)、交叉编译到板端推理的全流程,重点讲解了如何利用RK3576的NPU进行硬件加速,实现高效的边缘AI应用。

weixin_30356433的博客 269

蓝桥杯校内选拔赛题目c语言,第六届蓝桥杯校内选拔赛C/C++高职组解题(6)

形如:1/a 的分数称为单位分数。能够把1分解为若干个互不相同的单位分数之和。例如:1 = 1/2 + 1/3 + 1/9 + 1/181 = 1/2 + 1/3 + 1/10 + 1/151 = 1/3 + 1/5 + 1/7 + 1/9 + 1/11 + 1/15 + 1/35 + 1/45 + 1/231等等,相似这样的分解无穷无尽。咱们增长一个约束条件:最大的分母必须不超过30请你求出分解...

weixin_33335559的博客 576

基于Spring Boot + Vue 3构建高并发华为数码商城交易平台:全栈架构设计与实现

内容将涵盖系统架构、数据库设计、核心模块开发(用户、商品、订单、购物车)、安全认证、性能优化以及前后端分离部署等关键环节,并提供详尽的代码示例,旨在为开发者提供一个可落地的企业级项目实战指南。<el-button text class="button" @click.stop="addToCart(product)">加入购物车</el-button>.antMatchers("/api/user/login", "/api/user/register").permitAll() // 公开接口。

2201_76125393的博客 307

第六届蓝桥杯校内选拔赛C/C++高职组解题(5)

把一个整数的每个数位都平方后求和,又得到一个整数,我们称这个整数为:位平方和。 对新得到的整数仍然可以继续这一运算过程。 比如,给定整数为4,则一系列的运算结果为: 16,37,58,89,.... 本题的要求是,已知一个整数x,求第n步的运算结果。 数据格式要求: 输入,两个整数x n,中间以空格分开。表示求x的第n步位平方和。其中,x

qq120267583的专栏 645

第3课:大模型集成与API设计

OpenAIAnthropicGoogle国内厂商:文心一言、通义千问、讯飞星火。

lpfasd123的博客 116

深度学习工具包 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")

第六届蓝桥杯校内选拔赛C/C++高职组解题(1)

二项式的系数规律,我国数学家很早就发现了。 如【图1.png】,我国南宋数学家杨辉1261年所著的《详解九章算法》一书里就出现了。 其排列规律: 1 1    1 1    2    1 1    3    3    1 1    4    6    4    1 1    5    10   10   5    1 1    6    15   20   15

qq120267583的专栏 1069

pscad IEEE标准系统搭建说明

pscad IEEE标准系统搭建说明,包含典型的IEEE 9节点、14节点、30节点、39节点和118节点系统。内含标准测试系统的原始数据和潮流结果。

第六届蓝桥杯校内选拔赛C/C++高职组解题(4)

1193是个素数,对它循环移位后发现: 1931,9311,3119也都是素数,这样特征的数叫:循环素数。 你能找出具有这样特征的5位数的循环素数吗? 当然,这样的数字可能有很多,请写出其中最大的一个。 注意:答案是个5位数,不要填写任何多余的内容。 答案 99371 代码 #include #include #include

qq120267583的专栏 1372

数学建模模型总结

这是本人在两年内准备参加数学建模竞赛搜集到的模型资料,已经经过了本人的筛选和整理,希望能够对准备参加数学建模竞赛的学弟学妹们提供一些帮助!

第六届蓝桥杯校内选拔赛C/C++高职组解题(3)

有如下的加法算式。其中每个汉字代表一个数字。 (如果存在对齐问题,可参见【图1.png】)                年              大年            过大年          能过大年        怎能过大年      我怎能过大年 +  让我怎能过大年 ------------------    能能能能能能能 请填写“让我怎

qq120267583的专栏 1238

调和级数近似求和公式推导

调和级数(Harmonic series)是一个发散的无穷级数 其中 为欧拉常数,  推导过程:

u010622506的博客 1万+

蓝桥杯 模拟试题2

1/1 + 1/2 + 1/3 + 1/4 + … 在数学上称为调和级数。它是发散的,也就是说,只要加上足够多的项,就可以得到任意大的数字。但是,它发散的很慢:前1项和达到 1.0 前4项和才超过 2.0 前83项的和才超过 5.0那么,请你计算一下,要加多少项,才能使得和达到或超过 15.0 呢?请填写这个整数。注意:只需要填写一个整数,不要填写任何多余的内容。比如说明文字。这个题直接纯暴力就

linlinsong—ACM界蒟水! 1793

调和级数

第五届蓝桥杯调和级数 1/1 + 1/2 + 1/3 + 1/4 + … 在数学上称为调和级数。 它是发散的,也就是说,只要加上足够多的项,就可以得到任意大的数字。 但是,它发散的很慢: 前1项和达到 1.0 前4项和才超过 2.0 前83项的和才超过 5.0 那么,请你计算一下,要加多少项,才能使得和达到或超过 15.0 呢? 请填写这个整数。 注意:只需要填写一个整数,不要填写任何多余的内容。...

qq_43191251的博客 2488

2015年省赛题

一、隔行变色 Answer: 15 Excel表的格子很多,为了避免把某行的数据和相邻行混淆,可以采用隔行变色的样式。 小明设计的样式为:第1行蓝色,第2行白色,第3行蓝色,第4行白色,… 现在小明想知道,从第21行到第50行一共包含了多少个蓝色的行。 请你直接提交这个整数,千万不要填写任何多余的内容。 这题直接看代码吧…… 代码块: public class _1隔行变色 { public s...

wnamej的博客 368

高数_第6章无穷级数__调和级数

所谓调和级数,是指 看一个例题证明: 级数 发散。证: 调和级数的部分和

华工的专栏 1584

调和级数求和

题目: 已知:Sn= 1+1/2+1/3+…+1/n。显然对于任意一个整数K,当n足够大的时候,Sn大于K。 现给出一个整数K(1<=k<=15),要求计算出一个最小的n;使得Sn>K。 输入: k 输出; n 打表AC #include<stdio.h> int main() { int n; int a[]= {1,2,4,11,31,83,227,61...

文轩 1万+
上一篇: 第六届蓝桥杯校内选拔赛C/C++高职组解题(1)
下一篇: 第六届蓝桥杯校内选拔赛C/C++高职组解题(3)
qq120267583
博客等级 码龄17年 2粉丝 7原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值