Cattle off the holiday season team 11 A Summation

A Summation

Topic links: https://ac.nowcoder.com/acm/contest/1077/A

Title Description

Known: S n- =. 1. 1 + / 2 +. 1 /. 3. 1 + ... + / n-. Clearly for any integer K, when n is large enough, S n is larger than K.
We are now given an integer K (1 <= k <= 15), requires a minimum of n-calculated; such S n- > K.

Enter a description:

Enter k

Output Description:

Output n
Example 1

Entry

1

Export

2 
ideas: the number of columns and can be superimposed, is greater than k to exit

//
// Created by HJYL on 2019/8/15.
//
#include <iostream>
#include <vector>
#include <map>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <algorithm>

#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
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;
}

 

Guess you like

Origin www.cnblogs.com/Vampire6/p/11372457.html
Recommended