結果

問題 No.195 フィボナッチ数列の理解(2)
ユーザー sugim48sugim48
提出日時 2015-04-26 23:09:42
言語 C++11
(gcc 11.4.0)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,991 bytes
コンパイル時間 878 ms
コンパイル使用メモリ 97,788 KB
実行使用メモリ 7,764 KB
最終ジャッジ日時 2023-09-18 09:34:57
合計ジャッジ時間 7,380 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#define _USE_MATH_DEFINES
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstring>
#include <cmath>
#include <fstream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<ll, int> ll_i;
typedef pair<double, int> d_i;
typedef pair<ll, ll> ll_ll;
typedef pair<double, double> d_d;
struct edge { int u, v; ll w; };

int INF = INT_MAX / 10;
ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

int main() {
	vector<ll> fib(51);
	fib[0] = 1; fib[1] = 0;
	for (int i = 2; i <= 50; i++)
		fib[i] = fib[i - 1] + fib[i - 2];
	vector<ll> v(3);
	cin >> v[0] >> v[1] >> v[2];
	sort(v.begin(), v.end());
	v.erase(unique(v.begin(), v.end()), v.end());
	int n = v.size();
	ll_ll ans(LLONG_MAX, LLONG_MAX);
	if (n == 1) {
		if (v[0]) ans = min(ans, ll_ll(v[0], 1));
		if (v[0]) ans = min(ans, ll_ll(1, v[0]));
		for (int i = 2; i < 50; i++) {
			ll a = fib[i], b = fib[i + 1];
			for (ll y = 1; y * b < v[0]; y++) {
				ll z = v[0] - y * b;
				if (z % a == 0) {
					ll x = z / a;
					if (x >= 1 && y >= 1)
						ans = min(ans, ll_ll(x, y));
				}
			}
		}
	}
	else {
	for (int i = 0; i < 50; i++)
		for (int j = i + 1; j < 50; j++)
			for (int k = j + 1; k < 50; k++) {
				ll a = fib[i], b = fib[i + 1];
				ll c = fib[j], d = fib[j + 1];
				ll det = a * d - b * c;
				ll z = v[0] * d - v[1] * b;
				if (z % det) continue;
				ll x = z / det;
				det = b * c - d * a;
				z = v[0] * c - v[1] * a;
				if (z % det) continue;
				ll y = z / det;
				if (n == 3 && (double)fib[k] * x + fib[k + 1] * y != v[2])
					continue;
				if (x >= 1 && y >= 1) ans = min(ans, ll_ll(x, y));
			}
	}
	if (ans.first == LLONG_MAX) cout << -1 << endl;
	else cout << ans.first << ' ' << ans.second << endl;
}
0