結果

問題 No.1278 どんな級数?
ユーザー 👑 hos.lyrichos.lyric
提出日時 2020-11-09 05:45:17
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 2,591 bytes
コンパイル時間 1,011 ms
コンパイル使用メモリ 117,868 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-29 21:55:32
合計ジャッジ時間 4,117 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 1 ms
4,380 KB
testcase_19 AC 1 ms
4,376 KB
testcase_20 AC 1 ms
4,376 KB
testcase_21 AC 1 ms
4,380 KB
testcase_22 AC 2 ms
4,380 KB
testcase_23 AC 2 ms
4,380 KB
testcase_24 AC 2 ms
4,376 KB
testcase_25 AC 2 ms
4,376 KB
testcase_26 AC 2 ms
4,380 KB
testcase_27 AC 2 ms
4,380 KB
testcase_28 AC 2 ms
4,376 KB
testcase_29 AC 2 ms
4,380 KB
testcase_30 AC 2 ms
4,380 KB
testcase_31 AC 1 ms
4,376 KB
testcase_32 AC 1 ms
4,380 KB
testcase_33 AC 1 ms
4,376 KB
testcase_34 AC 1 ms
4,376 KB
testcase_35 AC 1 ms
4,376 KB
testcase_36 AC 2 ms
4,380 KB
testcase_37 AC 1 ms
4,376 KB
testcase_38 AC 2 ms
4,376 KB
testcase_39 AC 1 ms
4,376 KB
testcase_40 AC 1 ms
4,376 KB
testcase_41 AC 2 ms
4,376 KB
testcase_42 AC 2 ms
4,376 KB
testcase_43 AC 1 ms
4,380 KB
testcase_44 AC 2 ms
4,376 KB
testcase_45 AC 2 ms
4,376 KB
testcase_46 AC 2 ms
4,376 KB
testcase_47 AC 1 ms
4,380 KB
testcase_48 AC 1 ms
4,376 KB
testcase_49 AC 2 ms
4,380 KB
testcase_50 AC 2 ms
4,380 KB
testcase_51 AC 1 ms
4,380 KB
testcase_52 AC 1 ms
4,380 KB
testcase_53 AC 2 ms
4,380 KB
testcase_54 AC 2 ms
4,380 KB
testcase_55 AC 2 ms
4,376 KB
testcase_56 AC 2 ms
4,376 KB
testcase_57 AC 2 ms
4,376 KB
testcase_58 AC 2 ms
4,376 KB
testcase_59 AC 1 ms
4,376 KB
testcase_60 AC 2 ms
4,380 KB
testcase_61 AC 1 ms
4,380 KB
testcase_62 AC 1 ms
4,380 KB
testcase_63 AC 1 ms
4,376 KB
testcase_64 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cassert>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

using Int = long long;

template <class T1, class T2> ostream &operator<<(ostream &os, const pair<T1, T2> &a) { return os << "(" << a.first << ", " << a.second << ")"; };
template <class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cerr << *i << " "; cerr << endl; }
template <class T> bool chmin(T &t, const T &f) { if (t > f) { t = f; return true; } return false; }
template <class T> bool chmax(T &t, const T &f) { if (t < f) { t = f; return true; } return false; }


/*
  f(a_1, ..., a_{n-1}, 2 b - 1) + f(a_1, ..., a_{n-1}, 2 b)
  = \sum_{1<k_1<...<k_{n-1}<l} k_1^{-a_1} ... k_{n-1}^{-a_{n-1}} l^{-2b}
  
  \sum_{a_1=1}^\infty ... \sum_{a_{n-1}}^\infty \sum_{b=1}^\infty
    \sum_{1<k_1<...<k_{n-1}<l} k_1^{-a_1} ... k_{n-1}^{-a_{n-1}} l^{-2b}
  = \sum_{1<k_1<...<k_{n-1}<l} 1 / (k_1 - 1) ... 1 / (k_{n-1} - 1) 1 / (l^2 - 1)
  
  \sum_{l=k+1}^\infty (1/2) (1 / (l - 1) + 1 / (l + 1))
  = (1/2) (1 / k + 1 / (k + 1))
  
  \sum_{l=k+1}^\infty (1 / (l - 1)) (p (1 / l) + q (1 / (l + 1)))
  = \sum_{l=k+1}^\infty (p (1 / (l - 1) - 1 / l) + (q/2) (1 / (l - 1) + 1 / (l + 1))
  = (p + q/2) (1 / l) + (q/2) (1 / (l + 1))
*/

/*
  f(a_1, ..., a_{n-1}, a_n) + f(a_1, ..., a_{n-1}, a_n - 1, 1)
  = z(a_n, ..., a_1) - z(a_n, ..., a_2) + ... + (-1)^{n-1} z(a_n) + (-1)^n
    (a_n >= 2)
  
  z(4) - 1
  z(3, 1) - z(3) + 1
  z(2, 2) - z(2) + 1
  z(2, 1, 1) - z(2, 1) + z(2) - 1
    total: 3 z(4) - 2 z(3)
  
  z(5) - 1
  z(4, 1) - z(4) + 1
  z(3, 2) - z(3) + 1
  z(2, 3) - z(2) + 1
  z(3, 1, 1) - z(3, 1) + z(3) - 1
  z(2, 2, 1) - z(2, 2) + z(2) - 1
  z(2, 1, 2) - z(2, 1) + z(2) - 1
  z(2, 1, 1, 1) - z(2, 1, 1) + z(2, 1) - z(2) + 1
    total: 4 z(5) - 3 z(4)
*/

int main() {
  int X, N;
  for (; ~scanf("%d%d", &X, &N); ) {
    double ans;
    switch (X) {
      case 1: {
        ans = 1.0 - pow(0.5, N + 1);
      } break;
      case 2: {
        if (N == 1) {
          ans = 0.5;
        } else if (N == 2) {
          ans = riemann_zeta(2) - 1.0;
        } else {
          ans = (N - 1) * riemann_zeta(N) - (N - 2) * riemann_zeta(N - 1);
        }
      } break;
      default: assert(false);
    }
    printf("%.12f\n", ans);
  }
  return 0;
}
0