結果
| 問題 | 
                            No.891 隣接3項間の漸化式
                             | 
                    
| コンテスト | |
| ユーザー | 
                             | 
                    
| 提出日時 | 2019-10-31 01:15:26 | 
| 言語 | C++14  (gcc 13.3.0 + boost 1.87.0)  | 
                    
| 結果 | 
                             
                                AC
                                 
                             
                            
                         | 
                    
| 実行時間 | 2 ms / 2,000 ms | 
| コード長 | 803 bytes | 
| コンパイル時間 | 872 ms | 
| コンパイル使用メモリ | 73,204 KB | 
| 実行使用メモリ | 5,376 KB | 
| 最終ジャッジ日時 | 2024-09-14 21:59:46 | 
| 合計ジャッジ時間 | 1,798 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge2 / judge5 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 39 | 
ソースコード
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
using namespace std;
typedef long long int ll;
ll mod=1e9+7;
ll a[2][2],b[2][2],c[2][2];
int main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	ll A,B,n; cin >> A >> B >> n;
	b[0][0]=b[1][1]=1;
	a[0][0]=A;
	a[0][1]=B;
	a[1][0]=1;
	a[1][1]=0;
	while(n){
		if(n%2){
			for(int i=0;i<4;i++){
				c[i/2][i%2]=b[i/2][i%2];
				b[i/2][i%2]=0;
			}
			for(int i=0;i<2;i++){
				for(int j=0;j<2;j++){
					for(int k=0;k<2;k++){
						(b[i][j]+=a[i][k]*c[k][j])%=mod;
					}
				}
			}
		}
		for(int i=0;i<4;i++){
			c[i/2][i%2]=a[i/2][i%2];
			a[i/2][i%2]=0;
		}
		for(int i=0;i<2;i++){
			for(int j=0;j<2;j++){
				for(int k=0;k<2;k++){
					(a[i][j]+=c[i][k]*c[k][j])%=mod;
				}
			}
		}
		n/=2;
	}
	cout << b[1][0] << endl;
}