結果

問題 No.1235 ζ関数
ユーザー kit84kit84
提出日時 2020-09-22 20:39:23
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 192 ms / 2,000 ms
コード長 1,473 bytes
コンパイル時間 258 ms
コンパイル使用メモリ 11,032 KB
実行使用メモリ 31,792 KB
最終ジャッジ日時 2023-09-08 18:22:08
合計ジャッジ時間 5,146 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 177 ms
31,688 KB
testcase_01 AC 174 ms
31,604 KB
testcase_02 AC 180 ms
31,664 KB
testcase_03 AC 182 ms
31,668 KB
testcase_04 AC 192 ms
31,640 KB
testcase_05 AC 189 ms
31,636 KB
testcase_06 AC 185 ms
31,592 KB
testcase_07 AC 178 ms
31,672 KB
testcase_08 AC 172 ms
31,656 KB
testcase_09 AC 175 ms
31,672 KB
testcase_10 AC 185 ms
31,748 KB
testcase_11 AC 176 ms
31,732 KB
testcase_12 AC 174 ms
31,688 KB
testcase_13 AC 174 ms
31,792 KB
testcase_14 AC 175 ms
31,664 KB
testcase_15 AC 174 ms
31,680 KB
testcase_16 AC 172 ms
31,668 KB
testcase_17 AC 173 ms
31,660 KB
testcase_18 AC 178 ms
31,692 KB
testcase_19 AC 177 ms
31,752 KB
testcase_20 AC 188 ms
31,600 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
#import collections as col
input=sys.stdin.readline
enum=enumerate
inf=1001001001
eps=1e-7
upb=1e+4
lmax=300

mod = 10**9+7
NN = 2 * 10**5
g1 = [1, 1] # factorial
g2 = [1, 1] # factorial^(-1)
inverse = [0, 1] # tmp

def linput(ty=int, cvt=list):
	return cvt(map(ty,input().split()))

def vinput(rep=1, ty=int, cvt=list):
	return cvt(ty(input().rstrip()) for _ in "*"*rep)

def modinv(x, mod=mod):
	return pow(x, mod-2, mod)

def ratioal(x, y, mod=mod):
	### = x/y (mod m)
	re = x * modinv(y)
	return re % mod

def facto(x, y, mod):
	### y*(y+1)*...*(x-1)*x
	### = x!/(y-1)!
	
	re = 1
	for i in range(y, x+1):
		re *= i
		re %= mod
	#print(re, file=sys.stderr)
	return re

def comb(n, r, mod=mod):
    if ( r<0 or r>n ):
        return 0
    #r = min(r, n-r)
    #return facto(n, n-r+1, mod) * g2[r] % mod
    return g1[n] * g2[r] * g2[n-r] % mod

def init_fac():
	for i in range( 2, NN + 1 ):
		g1.append( ( g1[-1] * i ) % mod )
		inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
		g2.append( (g2[-1] * inverse[-1]) % mod )

init_fac()

def zeta(s):
	out = 0.
	pp = float(inf)
	
	for m in range(1,lmax+1):
		ins = 0.
		for j in range(1,m+1):
			c1 = (-1)**(j-1)
			c2 = comb(m-1, j-1)
			c3 = j**(-s)
			ins += c1*c2*c3
		ins *= 2**(-m) / (1 - 2**(1-s))
		out += ins
	
		if abs(pp - ins) < eps:
			break
		if abs(out) > upb:
			break
		
		pp = ins
	
	return out


def main():
	N, = linput()

	res = zeta(N)
	print(res)


if __name__=="__main__":
	main()
0