結果

問題 No.195 フィボナッチ数列の理解(2)
ユーザー antaanta
提出日時 2015-11-14 06:35:08
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 1,029 bytes
コンパイル時間 632 ms
コンパイル使用メモリ 69,520 KB
実行使用メモリ 4,368 KB
最終ジャッジ日時 2023-10-11 17:40:43
合計ジャッジ時間 2,050 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <vector>
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
using namespace std;
typedef long long ll;
const ll INFL = 1LL<<62;

int main() {
	int X[3];
	cin >> X[0] >> X[1] >> X[2];
	sort(X, X + 3);
	if(X[0] == X[2])
		X[0] = 1;
	vector<ll> f = {1, 0};
	while(f.back() < X[2])
		f.push_back(f.end()[-1] + f.end()[-2]);
	int n = f.size() - 1;
	pair<ll, ll> ans(INFL,INFL);
	vector<ll> v;
	rep(i, n) rep(j, n) if(i != j) {
		ll det = f[i] * f[j+1] - f[i+1] * f[j];
		if(det == 0) continue;
		ll xnum = X[0] * f[j+1] - X[2] * f[i+1];
		ll ynum = X[2] * f[i] - X[0] * f[j];
		if(xnum % det != 0 || ynum % det != 0) continue;
		ll x = xnum / det, y = ynum / det;
		if(x <= 0 || y <= 0) continue;
		v = { x, y };
		while(v.back() < X[1])
			v.push_back(v.end()[-1] + v.end()[-2]);
		if(find(v.begin(), v.end(), X[1]) != v.end())
			ans = min(ans, make_pair(x, y));
	}
	if(ans.first == INFL)
		cout << "-1" << endl;
	else
		cout << ans.first << " " << ans.second << endl;
	return 0;
}
0