結果

問題 No.891 隣接3項間の漸化式
ユーザー tactac
提出日時 2019-09-20 22:36:12
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,671 bytes
コンパイル時間 1,399 ms
コンパイル使用メモリ 165,832 KB
実行使用メモリ 8,696 KB
最終ジャッジ日時 2023-10-12 20:12:38
合計ジャッジ時間 10,765 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
8,696 KB
testcase_01 AC 1 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 1 ms
4,348 KB
testcase_14 WA -
testcase_15 AC 1 ms
4,356 KB
testcase_16 AC 1 ms
4,348 KB
testcase_17 AC 1 ms
4,352 KB
testcase_18 AC 1 ms
4,348 KB
testcase_19 AC 1 ms
4,348 KB
testcase_20 WA -
testcase_21 AC 1 ms
4,352 KB
testcase_22 AC 2 ms
4,352 KB
testcase_23 WA -
testcase_24 AC 1 ms
4,348 KB
testcase_25 TLE -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
#define inf (int)(1e9+7)
#define abs(x) (x >= 0 ? x : -(x))
#define ceil(a, b) a / b + !!(a % b)
template<typename T1, typename T2> inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }
template<typename T> T pow(T a, int b) { return b ? pow(a * a, b / 2) * (b % 2 ? a : 1) : 1; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }


const ll mod = 1e9 + 7;

int modpow(int a, int b) {
    if (b == 0) return 1;
    return (modpow((ll)a * a % mod, b / 2) % mod * (b % 2 ? a : 1) % mod) % mod;
}


int main() {
    int a, b, n;
    cin >> a >> b >> n;
    
    if (a == 0 && b == 0) {
        cout << 0 << endl;
        return 0;
    } else if (a == 0) {
        if (n % 2 == 0) cout << 0 << endl;
        else {
            cout << modpow(b, n / 2) << endl;
        }
        return 0;
    } else if (b == 0) {
        cout << modpow(a, n - 1) << endl;
        return 0;
    }
    double al, be;
    al = (a + sqrt(a * a + 4 * b)) / 2;
    be = (a - sqrt(a * a + 4 * b)) / 2;
    // cout << al << " " << be << endl;
    ll x = 0, y = 1;
    rep3(i, 2, n + 1) {
        ll z = (ll)((al * y + pow(be, i - 1)) + mod) % mod;
        // cout << pow(be, i - 1) << " " << z << endl;
        x = y;
        y = z;
    }
    cout << y << endl;
}
0