結果

問題 No.195 フィボナッチ数列の理解(2)
ユーザー shotoyooshotoyoo
提出日時 2021-06-28 22:59:17
言語 PyPy3
(7.3.15)
結果
RE  
実行時間 -
コード長 1,713 bytes
コンパイル時間 918 ms
コンパイル使用メモリ 86,916 KB
実行使用メモリ 79,320 KB
最終ジャッジ日時 2023-09-08 00:04:37
合計ジャッジ時間 5,596 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
testcase_01 RE -
testcase_02 RE -
testcase_03 RE -
testcase_04 RE -
testcase_05 RE -
testcase_06 RE -
testcase_07 RE -
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
testcase_19 RE -
testcase_20 RE -
testcase_21 RE -
testcase_22 RE -
testcase_23 RE -
testcase_24 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = lambda : sys.stdin.readline().rstrip()

sys.setrecursionlimit(2*10**5+10)
write = lambda x: sys.stdout.write(x+"\n")
debug = lambda x: sys.stderr.write(x+"\n")
writef = lambda x: print("{:.12f}".format(x))

import numpy as np
x,y,z = list(map(int, input().split()))
f = [1,1]
for i in range(31):
    f.append(f[-2]+f[-1])
s = set([x,y,z])
ans = None
if len(s)==1:
    a = 1
    for i in range(30)[::-1]:
        if (x - f[i]) % f[i+1] == 0 and (x-f[i])//f[i+1]>0:
            b = (x-f[i])//f[i+1]
            ans = (a,b)
            break
    else:
        if x==1:
            ans = (1,1)
        else:
            ans = (1, x-1)
elif len(s)==2:
    x,y = s
    ans = None
    for i in range(30):
        for j in range(30):
            if i==j:
                continue
            v1,v2 = np.linalg.solve([[f[i], f[i+1]], [f[j], f[j+1]]], [x,y])
            if v1>0 and v2>0 and (ans is None or (v1,v2)<ans):
                ans = (int(v1+0.1), int(v2+0.1))
    if ans is None:
        ans = (-1,)
else:
    x,y,z = s
    ans = None
    for i in range(30):
        for j in range(30):
            if i==j:
                continue
            v1,v2 = np.linalg.solve([[f[i], f[i+1]], [f[j], f[j+1]]], [x,y])
#             if i==4 and j==6:
#                 print(i,j,v1,v2)
            if not (abs(v1 - round(v1))<1e-6 and abs(v2-round(v2)) <1e-6):
                continue
            for k in range(30):
                if abs(f[k]*v1 + f[k+1]*v2 - z) < 1e-7:
                    if v1>0 and v2>0:
                        if (ans is None or (v1,v2)<ans):
                            ans = (int(v1+0.1), int(v2+0.1))
                    
    if ans is None:
        ans = (-1,)
print(*ans)
0