結果

問題 No.891 隣接3項間の漸化式
ユーザー totori_nyaa
提出日時 2019-09-20 21:59:12
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 473 bytes
コンパイル時間 2,239 ms
コンパイル使用メモリ 166,352 KB
実行使用メモリ 10,752 KB
最終ジャッジ日時 2024-09-14 17:30:15
合計ジャッジ時間 6,720 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 13 WA * 9 TLE * 1 -- * 16
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(20);

    
    ll mod = 1e9+7;
    ll a,b,n;
    cin>>a>>b>>n;
    ll x[3];
    x[0]=0,x[1]=1,x[2]=a;
    for(int i=3;i<=n;i++){
        x[i%3] = (a*x[(i+2)%3])%mod + (b*x[(i+1)%3])%mod;
        x[i%3] %= mod;
        if(i==n){
            cout << x[i%3] << "\n";
            return 0;
        } 
    }



}
0