結果

問題 No.195 フィボナッチ数列の理解(2)
ユーザー yaoshimaxyaoshimax
提出日時 2015-05-15 02:23:29
言語 PyPy2
(7.3.15)
結果
AC  
実行時間 91 ms / 5,000 ms
コード長 1,952 bytes
コンパイル時間 160 ms
コンパイル使用メモリ 77,732 KB
実行使用メモリ 78,952 KB
最終ジャッジ日時 2023-09-20 07:56:04
合計ジャッジ時間 3,523 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 77 ms
76,264 KB
testcase_01 AC 78 ms
76,624 KB
testcase_02 AC 91 ms
78,648 KB
testcase_03 AC 79 ms
76,648 KB
testcase_04 AC 84 ms
78,656 KB
testcase_05 AC 78 ms
76,364 KB
testcase_06 AC 77 ms
76,364 KB
testcase_07 AC 77 ms
76,224 KB
testcase_08 AC 76 ms
76,152 KB
testcase_09 AC 78 ms
76,640 KB
testcase_10 AC 85 ms
78,952 KB
testcase_11 AC 84 ms
78,676 KB
testcase_12 AC 85 ms
78,924 KB
testcase_13 AC 86 ms
78,648 KB
testcase_14 AC 84 ms
78,792 KB
testcase_15 AC 84 ms
78,612 KB
testcase_16 AC 85 ms
78,744 KB
testcase_17 AC 85 ms
78,848 KB
testcase_18 AC 83 ms
78,504 KB
testcase_19 AC 83 ms
78,864 KB
testcase_20 AC 83 ms
78,812 KB
testcase_21 AC 84 ms
78,756 KB
testcase_22 AC 84 ms
78,572 KB
testcase_23 AC 83 ms
78,780 KB
testcase_24 AC 83 ms
78,740 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 or (x*F10[j]-y*F10[i])%(F10[j]*F01[i]-F01[j]*F10[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
            (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 or (x*F10[j]-y*F10[i])%(F10[j]*F01[i]-F01[j]*F10[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