洛谷-P1035 级数求和

原题连接https://www.luogu.org/problem/P1035

题目描述

已知:Sn=1+1/2+1/3+…+1/n。显然对于任意一个整数 k,当 n 足够大的时候,Sn>K

输入格式

一个正整数 k

输出格式

一个正整数 n

输入输出样例

输入
1
输出
2

说明/提示

【数据范围】
对于 100% 的数据,1≤k≤15

Java解题

GitHub连接https://github.com/JackWei1996/BrushProblem/blob/master/src/com/jackwei/luogu/P1046.java

public class P1035 {
    public static void main(String[] args) {
        //查表法,已知就这些数,先算出来对应查表即可。
        /* int i = 1;
         int j = 2;

         double k = 1;

         while (i<16){
              for (; j<100000000; j++){
                 k += 1.0/j;
                 if (i < k){
                      System.out.println(i+"========"+j +"========"+k);
                      i++;
                      j++;
                      break;
                  }
              }
          }*/

        int[] table = {2, 4, 11, 31, 83, 227, 616, 1674, 4550, 12367, 33617, 91380, 248397, 675214, 1835421};

        int i = new Scanner(System.in).nextInt();
        System.out.println(table[i-1]);
    }
}
发布了172 篇原创文章 · 获赞 64 · 访问量 16万+

猜你喜欢

转载自blog.csdn.net/WeiHao0240/article/details/103122935