結果
| 問題 |
No.891 隣接3項間の漸化式
|
| コンテスト | |
| ユーザー |
milanis48663220
|
| 提出日時 | 2019-09-20 22:32:56 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 2,000 ms |
| コード長 | 1,125 bytes |
| コンパイル時間 | 495 ms |
| コンパイル使用メモリ | 55,128 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-09-14 18:28:22 |
| 合計ジャッジ時間 | 1,647 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge6 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 39 |
ソースコード
#include <iostream>
using namespace std;
typedef long long ll;
const ll MOD = 1000000007;
void prod(ll a[2][2], ll b[2][2], ll ans[2][2]){
for(int i = 0; i < 2; i++){
for(int j = 0; j < 2; j++){
ans[i][j] = 0;
for(int k = 0; k < 2; k++){
ans[i][j] += a[i][k]*b[k][j];
ans[i][j] %= MOD;
}
}
}
}
void copy(ll a[2][2], ll b[2][2]){
for(int i = 0; i < 2; i++){
for(int j = 0; j < 2; j++){
b[i][j] = a[i][j];
}
}
}
void pow(ll a[2][2], ll n, ll ans[2][2]){
ll buf[2][2];
ll tmp[2][2];
copy(a, tmp);
ans[0][0] = 1; ans[1][1] = 1;
ans[0][1] = 0; ans[1][0] = 0;
for(int i = 0; i <= 30; i++){
ll m = (ll)1 << i;
if(m&n){
prod(tmp, ans, buf);
copy(buf, ans);
}
prod(tmp, tmp, buf);
copy(buf, tmp);
}
}
int main(){
ll a, b, n;
cin >> a >> b >> n;
ll s[2][2];
ll ans[2][2];
s[0][0] = a;
s[0][1] = b;
s[1][0] = 1;
s[1][1] = 0;
pow(s, n, ans);
cout << ans[1][0] << endl;
}
milanis48663220