結果
問題 | No.534 フィボナッチフィボナッチ数 |
ユーザー | Pachicobue |
提出日時 | 2017-06-28 18:41:41 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 2 ms / 2,000 ms |
コード長 | 4,224 bytes |
コンパイル時間 | 1,285 ms |
コンパイル使用メモリ | 167,208 KB |
実行使用メモリ | 6,824 KB |
最終ジャッジ日時 | 2024-10-04 14:52:30 |
合計ジャッジ時間 | 2,313 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
6,816 KB |
testcase_01 | AC | 1 ms
6,816 KB |
testcase_02 | AC | 1 ms
6,816 KB |
testcase_03 | AC | 1 ms
6,816 KB |
testcase_04 | AC | 1 ms
6,816 KB |
testcase_05 | AC | 1 ms
6,816 KB |
testcase_06 | AC | 1 ms
6,820 KB |
testcase_07 | AC | 2 ms
6,816 KB |
testcase_08 | AC | 1 ms
6,816 KB |
testcase_09 | AC | 1 ms
6,816 KB |
testcase_10 | AC | 2 ms
6,816 KB |
testcase_11 | AC | 2 ms
6,820 KB |
testcase_12 | AC | 1 ms
6,816 KB |
testcase_13 | AC | 1 ms
6,820 KB |
testcase_14 | AC | 2 ms
6,820 KB |
testcase_15 | AC | 1 ms
6,816 KB |
testcase_16 | AC | 2 ms
6,820 KB |
testcase_17 | AC | 1 ms
6,816 KB |
testcase_18 | AC | 1 ms
6,816 KB |
testcase_19 | AC | 2 ms
6,820 KB |
testcase_20 | AC | 2 ms
6,820 KB |
testcase_21 | AC | 1 ms
6,816 KB |
testcase_22 | AC | 2 ms
6,820 KB |
testcase_23 | AC | 1 ms
6,824 KB |
testcase_24 | AC | 1 ms
6,820 KB |
testcase_25 | AC | 1 ms
6,816 KB |
testcase_26 | AC | 1 ms
6,816 KB |
testcase_27 | AC | 1 ms
6,820 KB |
testcase_28 | AC | 1 ms
6,816 KB |
testcase_29 | AC | 1 ms
6,816 KB |
testcase_30 | AC | 1 ms
6,816 KB |
testcase_31 | AC | 1 ms
6,816 KB |
testcase_32 | AC | 1 ms
6,820 KB |
testcase_33 | AC | 1 ms
6,816 KB |
testcase_34 | AC | 2 ms
6,820 KB |
testcase_35 | AC | 1 ms
6,816 KB |
testcase_36 | AC | 2 ms
6,820 KB |
testcase_37 | AC | 1 ms
6,824 KB |
testcase_38 | AC | 1 ms
6,816 KB |
testcase_39 | AC | 2 ms
6,816 KB |
testcase_40 | AC | 1 ms
6,820 KB |
testcase_41 | AC | 1 ms
6,816 KB |
ソースコード
#include <bits/stdc++.h> using namespace std; #define FOR(i, a, b) for (ll i = (a); i < (b); i++) #define RFOR(i, a, b) for (ll i = (b)-1; i >= (a); i--) #define rep(i, n) for (ll i = 0; i < (n); i++) #define rep1(i, n) for (ll i = 1; i <= (n); i++) #define rrep(i, n) for (ll i = (n)-1; i >= 0; i--) #define pb push_back #define mp make_pair #define fst first #define snd second #define show(x) cout << #x << " = " << x << endl #define chmin(x, y) x = min(x, y) #define chmax(x, y) x = max(x, y) #define pii pair<int, int> namespace is_stl_container_impl { template <typename T> struct is_stl_container : false_type { }; template <typename T, size_t N> struct is_stl_container<array<T, N>> : true_type { }; template <typename... Args> struct is_stl_container<vector<Args...>> : true_type { }; template <typename... Args> struct is_stl_container<deque<Args...>> : true_type { }; template <typename... Args> struct is_stl_container<list<Args...>> : true_type { }; template <typename... Args> struct is_stl_container<forward_list<Args...>> : true_type { }; template <typename... Args> struct is_stl_container<set<Args...>> : true_type { }; template <typename... Args> struct is_stl_container<multiset<Args...>> : true_type { }; template <typename... Args> struct is_stl_container<map<Args...>> : true_type { }; template <typename... Args> struct is_stl_container<multimap<Args...>> : true_type { }; template <typename... Args> struct is_stl_container<unordered_set<Args...>> : true_type { }; template <typename... Args> struct is_stl_container<unordered_multiset<Args...>> : true_type { }; template <typename... Args> struct is_stl_container<unordered_map<Args...>> : true_type { }; template <typename... Args> struct is_stl_container<unordered_multimap<Args...>> : true_type { }; template <typename... Args> struct is_stl_container<stack<Args...>> : true_type { }; template <typename... Args> struct is_stl_container<queue<Args...>> : true_type { }; template <typename... Args> struct is_stl_container<priority_queue<Args...>> : true_type { }; } // namespace is_stl_container_impl //type trait to utilize the implementation type traits as well as decay the type template <typename T> struct is_stl_container { static constexpr bool const value = is_stl_container_impl::is_stl_container<decay_t<T>>::value; }; template <typename T> typename enable_if<is_stl_container<T>::value, ostream&>::type operator<<(ostream& os, const T& container) { os << "["; for (const auto& p : container) { os << p << ","; } os << "]"; return os; } template <typename S, typename T> ostream& operator<<(ostream& os, const pair<S, T>& p) { os << "(" << p.first << "," << p.second << ")"; return os; } using ll = unsigned long long; constexpr ll MOD = 1000000007; constexpr ll PERIOD = (MOD + 1) * 2; template <typename T> constexpr T INF = numeric_limits<T>::inf() / 100; struct Matrix { Matrix(const ll m) : mod{m} { value[0][0] = 1; value[0][1] = 0; value[1][0] = 0; value[1][1] = 1; } Matrix operator*(const Matrix& mat) const { Matrix m(mod); for (int i = 0; i < 2; i++) { for (int j = 0; j < 2; j++) { m.value[i][j] = 0; for (int k = 0; k < 2; k++) { m.value[i][j] += (value[i][k] * mat.value[k][j]) % mod; m.value[i][j] = m.value[i][j] % mod; } } } return m; } const ll mod; ll value[2][2]; }; Matrix power(const Matrix& mat, const ll n, const ll mod) { if (n == 0) { return Matrix{mod}; } if (n % 2 == 1) { return mat * power(mat, n - 1, mod); } else { const auto p = power(mat, n / 2, mod); return p * p; } } ll fib(const ll n, const ll mod) { if (n == 0) { return 0; } else if (n == 0) { return 1; } Matrix mat(mod); mat.value[0][0] = 0; mat.value[0][1] = 1; mat.value[1][0] = 1; mat.value[1][1] = 1; return power(mat, n - 1, mod).value[1][1]; } int main() { ll X; cin >> X; const ll p = fib(X, PERIOD); cout << fib(p, MOD) << endl; return 0; }