博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
牛客假日团队赛11 A 级数求和
阅读量:4556 次
发布时间:2019-06-08

本文共 769 字,大约阅读时间需要 2 分钟。

A级数求和

题目链接:

题目描述

已知:S
n= 1+1/2+1/3+…+1/n。显然对于任意一个整数K,当n足够大的时候,S
n大于K。
现给出一个整数K(1<=k<=15),要求计算出一个最小的n;使得S
n>K。

输入描述:

输入k

输出描述:

输出n
示例1

输入

1

输出

2 思路:叠加数列和即可,大于k退出即可
//// Created by HJYL on 2019/8/15.//#include 
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;typedef long long ll;const int maxn=1e6+10;int main(){ int k; scanf("%d",&k); double res=1; for(int i=1;;i++) { res += double((double) 1 / double(i + 1)); if (res > k) { printf("%d\n", i + 1); break; } } return 0;}

 

转载于:https://www.cnblogs.com/Vampire6/p/11372457.html

你可能感兴趣的文章
Search Insert Position
查看>>
数据可视化(5)--jqplot经典实例
查看>>
u盘复制提示文件过大
查看>>
grails项目数据源配置
查看>>
mysql数据库索引简单原理
查看>>
【爱笑话7.0版】笑话两万篇,免费阅读,绝无广告
查看>>
The square chest
查看>>
不用第三个变量实现a,b的值交换
查看>>
四则运算
查看>>
为VS2010默认模板添加版权信息(转)
查看>>
int类型属性判空
查看>>
remote: ERROR: missing Change-Id in commit message footer
查看>>
js中的事件总结
查看>>
关于Unity实现三维物体裁剪功能
查看>>
BZOJ4033 [HAOI2015]树上染色 【树形dp】
查看>>
POJ 3659 Cell Phone Network 最小支配集模板题(树形dp)
查看>>
最少构造出回文 (最长公共子序列+思维)
查看>>
20135201李辰希 《Linux内核分析》第四周 扒开系统调用的“三层皮”
查看>>
如何快速的开发一个完整的iOS直播app(美颜篇)
查看>>
基于node.js+socket.io+html5实现的斗地主游戏(1)概述
查看>>