結果

問題 No.195 フィボナッチ数列の理解(2)
ユーザー 沙耶花沙耶花
提出日時 2021-11-04 06:33:19
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,218 bytes
コンパイル時間 5,382 ms
コンパイル使用メモリ 263,432 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-22 03:11:11
合計ジャッジ時間 5,624 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <stdio.h>
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace atcoder;
using mint = modint1000000007;
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define Inf 1000000002


int main(){	
	
	vector<long long> x(3);
	rep(i,3)cin>>x[i];
	
	sort(x.begin(),x.end());
	
	
	
	vector<long long> A(2,0),B(2,0);
	A[0] = 1;
	B[1] = 1;
	
	while(A.back()<Inf&&B.back()<Inf){
		int n = A.size();
		A.push_back(A[n-1]+A[n-2]);
		B.push_back(B[n-1]+B[n-2]);
	}
	vector<pair<long long,long long>> ans;
	if(x[0]==x[2]){
		ans.emplace_back(1,x[0]);
		rep(i,A.size()){
			long long t = x[0] - A[i];
			if(t<=0)break;
			if(i<=1)continue;
			if(t%B[i]!=0)continue;
			ans.emplace_back(1,t/B[i]);
		}
	
	}
	else{
		if(x[0]==x[1])swap(x[1],x[2]);
		
		rep(i,A.size()){
			for(int j=i+1;j<A.size();j++){
				long long xa = A[i],ya = B[i],za = x[0];
				long long xb = A[j],yb = B[j],zb = x[1];
				long long xx,yy;
				if(xa!=0&&xb!=0){
					long long l = lcm(xa,xb);
					za *= l/xa;
					ya *= l/xa;
					zb *= l/xb;
					yb *= l/xb;
					if((za-zb)%(ya-yb)!=0)continue;
					yy = (za-zb)/(ya-yb);
					if(yy<=0)continue;
					xa=  A[i],ya = B[i],za = x[0];
					za -= ya * yy;
					if(za % xa != 0)continue;
					xx = za/xa;
					if(xx<=0)continue;
				}
				else continue;
				
				rep(k,A.size()){
					
					if(xx * A[k] + yy * B[k] == x[2]){
						ans.emplace_back(xx,yy);
						
					}
					
				}
			}
		}
		rep(i,A.size()){
			rep(j,i){
				long long xa = A[i],ya = B[i],za = x[0];
				long long xb = A[j],yb = B[j],zb = x[1];
				long long xx,yy;
				if(xa!=0&&xb!=0){
					long long l = lcm(xa,xb);
					za *= l/xa;
					ya *= l/xa;
					zb *= l/xb;
					yb *= l/xb;
					if((za-zb)%(ya-yb)!=0)continue;
					yy = (za-zb)/(ya-yb);
					if(yy<=0)continue;
					xa=  A[i],ya = B[i],za = x[0];
					za -= ya * yy;
					if(za % xa != 0)continue;
					xx = za/xa;
					if(xx<=0)continue;
				}
				else continue;
				
				rep(k,A.size()){
					
					if(xx * A[k] + yy * B[k] == x[2]){
						ans.emplace_back(xx,yy);
						
					}
					
				}
			}
		}
	}
	if(ans.size()==0)cout<<-1<<endl;
	else{
		sort(ans.begin(),ans.end());
		cout<<ans[0].first<<' '<<ans[0].second<<endl;
	}
	
	return 0;
	
}
0