結果

問題 No.195 フィボナッチ数列の理解(2)
ユーザー 👑 NachiaNachia
提出日時 2021-02-06 18:50:39
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 931 bytes
コンパイル時間 2,007 ms
コンパイル使用メモリ 200,944 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-16 05:10:20
合計ジャッジ時間 3,050 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using LL=long long;
using ULL=unsigned long long;
#define rep(i,n) for(int i=0; i<(n); i++)

LL X,Y,Z;
LL F[45];
int main(){
  cin>>X>>Y>>Z;
  if(X!=Z) swap(Y,Z);
  if(Y!=Z) swap(X,Z);
  F[0]=1;F[1]=0;
  for(int i=2; i<45; i++) F[i]=F[i-1]+F[i-2];
  pair<LL,LL> ans={1000000000000,-1};
  if(X!=Y) rep(i,44) rep(j,44){
    LL D=F[j+1]*F[i]-F[i+1]*F[j];
    if(D==0) continue;
    LL A=F[j+1]*X-F[i+1]*Y;
    LL B=F[i]*Y-F[j]*X;
    if(A%D) continue; A/=D; if(A<=0) continue;
    if(B%D) continue; B/=D; if(B<=0) continue;
    bool ok=false;
    rep(k,44) if(Z==A*F[k]+B*F[k+1]) ok=true;
    if(!ok) continue;
    ans=min(ans,make_pair(A,B));
  }
  else for(int i=1; i<44; i++){
    LL B=X-F[i]; if(B%F[i+1]) continue; B/=F[i+1]; if(B<=0) continue;
    ans=min(ans,make_pair(1ll,B));
  }
  if(ans.second==-1) cout<<-1<<endl;
  else cout<<ans.first<<" "<<ans.second<<endl;
  return 0;
}
0