結果

問題 No.195 フィボナッチ数列の理解(2)
ユーザー yaoshimaxyaoshimax
提出日時 2015-05-15 02:19:18
言語 PyPy2
(7.3.15)
結果
WA  
実行時間 -
コード長 1,712 bytes
コンパイル時間 273 ms
コンパイル使用メモリ 78,028 KB
実行使用メモリ 79,176 KB
最終ジャッジ日時 2023-09-20 07:55:47
合計ジャッジ時間 3,510 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 75 ms
76,556 KB
testcase_01 AC 75 ms
76,168 KB
testcase_02 AC 80 ms
78,788 KB
testcase_03 AC 74 ms
76,268 KB
testcase_04 AC 80 ms
78,996 KB
testcase_05 AC 79 ms
76,404 KB
testcase_06 AC 74 ms
76,492 KB
testcase_07 AC 75 ms
76,304 KB
testcase_08 AC 74 ms
76,304 KB
testcase_09 AC 73 ms
76,260 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 80 ms
78,844 KB
testcase_13 WA -
testcase_14 AC 80 ms
79,056 KB
testcase_15 AC 80 ms
78,772 KB
testcase_16 AC 82 ms
78,848 KB
testcase_17 AC 81 ms
78,872 KB
testcase_18 AC 81 ms
78,888 KB
testcase_19 AC 82 ms
78,708 KB
testcase_20 AC 81 ms
78,912 KB
testcase_21 AC 82 ms
78,872 KB
testcase_22 AC 82 ms
78,904 KB
testcase_23 AC 82 ms
79,176 KB
testcase_24 AC 84 ms
78,868 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

F10=[0 for i in range(50)]
F01=[0 for i in range(50)]
F10[0]=1
F01[1]=1
for i in range(2,50):
    F10[i]=F10[i-1]+F10[i-2]
    F01[i]=F01[i-1]+F01[i-2]
X=map(int,raw_input().split())
X=list(set(X))
X.sort()
if len(X)==1:
    a=1
    ans=1000000000
    for i in range(50):
        if F01[i]==0:
            if F10[i]==X[0]:
                ans=min(ans,1)
        elif (X[0]-F10[i])%F01[i]==0 and X[0]-F10[i]>0:
            ans =min(ans,(X[0]-F10[i])/F01[i])
    print a,ans
elif len(X)==2:
    x,y=X[0],X[1]
    A,B=1000000000,1000000000
    for i in range(50):
        for j in range(i+1,50):
            if(x*F01[j]-y*F01[i])%(F01[j]*F10[i]-F10[j]*F01[i])!=0:
                continue
            a=(x*F01[j]-y*F01[i])/(F01[j]*F10[i]-F10[j]*F01[i])
            b=(x*F10[j]-y*F10[i])/(F10[j]*F01[i]-F01[j]*F10[i])
            if a<=0 or b<=0:
                continue
            (A,B)=min((A,B),(a,b))
    print A,B
else:
    x,y,z=X[0],X[1],X[2]
    A,B=1000000000,1000000000
    for i in range(50):
        for j in range(i+1,50):
            if(x*F01[j]-y*F01[i])%(F01[j]*F10[i]-F10[j]*F01[i])!=0:
                continue
            a=(x*F01[j]-y*F01[i])/(F01[j]*F10[i]-F10[j]*F01[i])
            b=(x*F10[j]-y*F10[i])/(F10[j]*F01[i]-F01[j]*F10[i])
            if a<=0 or b<=0:
                continue
            #print x,"=",a,"*",F10[i],"+",b,"*",F01[i],"...",i
            #print y,"=",a,"*",F10[j],"+",b,"*",F01[j],"...",j
            ok=False
            for k in range(j+1,50):
                if a*F10[k]+b*F01[k]==z:
                    ok=True
                    break
            if ok:
                (A,B)=min((A,B),(a,b))
    if A==1000000000:
        print -1
    else:
        print A,B
0