結果
| 問題 | 
                            No.891 隣接3項間の漸化式
                             | 
                    
| コンテスト | |
| ユーザー | 
                             queee
                         | 
                    
| 提出日時 | 2020-01-04 11:32:59 | 
| 言語 | C++14  (gcc 13.3.0 + boost 1.87.0)  | 
                    
| 結果 | 
                             
                                TLE
                                 
                             
                            
                         | 
                    
| 実行時間 | - | 
| コード長 | 352 bytes | 
| コンパイル時間 | 583 ms | 
| コンパイル使用メモリ | 64,212 KB | 
| 実行使用メモリ | 13,640 KB | 
| 最終ジャッジ日時 | 2024-11-22 20:07:06 | 
| 合計ジャッジ時間 | 43,299 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge1 / judge5 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 27 TLE * 12 | 
ソースコード
#include <iostream>
using namespace std;
typedef long long ll;
const ll mod = 1e9+7;
int main(void){
  ll a,b,n; cin >>a>>b>>n;
  if (n<=1) {cout<<n<<endl; return 0;}
  ll p[3]={0,1, -1};
  for(int i=2; i<=n; i++) {
    p[i%3] = (b*p[(i+1)%3] + a*p[(i+2)%3])%mod;
    //p[0]=p[1]; p[1]=p[2]; p[2]=(b*p[0]+a*p[1]) % mod;
  }
  
  cout<<p[n%3]<<endl;
}
            
            
            
        
            
queee