結果

問題 No.454 逆2乗和
ユーザー antaanta
提出日時 2016-12-05 12:55:38
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 2,343 bytes
コンパイル時間 2,543 ms
コンパイル使用メモリ 164,516 KB
実行使用メモリ 4,388 KB
最終ジャッジ日時 2023-08-20 03:16:58
合計ジャッジ時間 2,854 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 1 ms
4,384 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 1 ms
4,388 KB
testcase_16 AC 1 ms
4,380 KB
testcase_17 AC 1 ms
4,376 KB
testcase_18 AC 1 ms
4,380 KB
testcase_19 AC 1 ms
4,380 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 2 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,380 KB
testcase_25 AC 1 ms
4,376 KB
testcase_26 AC 2 ms
4,384 KB
testcase_27 AC 2 ms
4,384 KB
testcase_28 AC 1 ms
4,380 KB
testcase_29 AC 1 ms
4,380 KB
testcase_30 AC 1 ms
4,376 KB
testcase_31 AC 1 ms
4,380 KB
testcase_32 AC 2 ms
4,380 KB
testcase_33 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h"
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))
static const int INF = 0x3f3f3f3f; static const long long INFL = 0x3f3f3f3f3f3f3f3fLL;
typedef vector<int> vi; typedef pair<int, int> pii; typedef vector<pair<int, int> > vpii; typedef long long ll;
template<typename T, typename U> static void amin(T &x, U y) { if(y < x) x = y; }
template<typename T, typename U> static void amax(T &x, U y) { if(x < y) x = y; }

int main() {
	double x;
	while(~scanf("%lf", &x)) {
		//PolyGamma[1,1+x]
		auto polygamma_1 = [](double x) {
			const int K = 50;
			const double coeffs[K + 1] = {
				1.6449340668482146681, -2.4041138063185761718, 3.246969701117774419,
				-4.147711020312174061, 5.086715306710188411, -6.050095633314071025,
				7.028541249302254992, -8.016065526879961479, 9.008942006185984086,
				-10.004896569681596, 11.00250956854761716, -12.00070732746758358,
				12.9981342063054163, -13.99206239306592106, 14.97633983302635615,
				-15.93782270469998779, 16.8510323939057687, -17.67168374767435881,
				18.33127302498742281, -18.73653878024439616, 18.77811503500766297,
				-18.35075522507402258, 17.38276117212563587, -15.8662970442640601,
				13.87645080497570576, -11.56849174048032319, 9.15041672705758742,
				-6.83837942153813288, 4.81037159407223056, -3.174128543836691298,
				1.958379681069062035, -1.126307539833646026, 0.601976101366390352,
				-0.298065000605006801, 0.1362801355590084179, -0.05733456213833759648,
				0.02210972594757063743, -0.00778128763075514072, 0.002487006287830406237,
				-0.0007177583233071391231, 0.0001857970744734773324, -0.00004279316712579212362,
				8.684541747026690099e-6, -1.534238234623818611e-6, 2.323309946299035521e-7,
				-2.955092706178223107e-8, 3.070341316858696484e-9, -2.5024249357916062498e-10,
				1.5003776010264562567e-11, -5.884182034692197727e-13, 1.1324274859070014118e-14
			};
			double sum = 0;
			double p = 1;
			for(int k = 0; k <= K; ++ k) {
				sum += coeffs[k] * p;
				p *= x;
			}
			return sum;
		};
		int m = (int)floor(x);
		double z = x - m;
		double ans = polygamma_1(z);
		for(int i = 1; i <= m; ++ i)
			ans -= 1. / ((i + z) * (i + z));
		printf("%.15f\n", (double)ans);
	}
	return 0;
}
0