結果

問題 No.344 ある無理数の累乗
ユーザー shobonvip
提出日時 2022-03-12 15:50:45
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 45 ms / 2,000 ms
コード長 588 bytes
コンパイル時間 153 ms
コンパイル使用メモリ 82,328 KB
実行使用メモリ 56,152 KB
最終ジャッジ日時 2024-09-16 23:06:06
合計ジャッジ時間 2,607 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 30
権限があれば一括ダウンロードができます

ソースコード

diff #

import math

from collections import defaultdict

n = int(input())
k = defaultdict(lambda:-1)
a = []

kuri = -1
offset = -1

i = 1
j = 1
for cnt in range(1010):
	if k[(i, j)] >= 0:
		offset = k[(i, j)]
		kuri = cnt - k[(i, j)]
		break
	a.append((i, j))
	k[(i, j)] = cnt
	i, j = (i+3*j)%1000, (i+j)%1000

#print(a)

#print(offset, kuri)

if n == 0:
	print(1)
elif n-1 < offset:
	if n % 2 == 1:
		print(a[n-1][0]*2%1000)
	else:
		print((a[n-1][0]*2 - 1)%1000)
else:
	targ = (n-1-offset) % kuri
	if n % 2 == 1:
		print(a[targ+offset][0]*2%1000)
	else:
		print((a[targ+offset][0]*2 - 1)%1000)
0