結果

問題 No.891 隣接3項間の漸化式
ユーザー akakimidori
提出日時 2019-09-20 21:47:31
言語 Rust
(1.83.0 + proconio)
結果
AC  
実行時間 1 ms / 2,000 ms
コード長 1,253 bytes
コンパイル時間 12,705 ms
コンパイル使用メモリ 400,576 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-09-14 17:09:58
合計ジャッジ時間 14,558 ms
ジャッジサーバーID
(参考情報)
judge6 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 39
権限があれば一括ダウンロードができます

ソースコード

diff #

fn run() {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    let mut it = s.trim().split_whitespace();
    let a: u64 = it.next().unwrap().parse().unwrap();
    let b: u64 = it.next().unwrap().parse().unwrap();
    let mut n: u64 = it.next().unwrap().parse().unwrap();
    const MOD: u64 = 1_000_000_007;
    let mut t = [[1, 0], [0, 1]];
    let mut s = [[a, b], [1, 0]];
    while n > 0 {
        if n & 1 == 1 {
            let mut c = [[0, 0], [0, 0]];
            for i in 0..2 {
                for j in 0..2 {
                    for k in 0..2 {
                        c[i][j] += t[i][k] * s[k][j];
                    }
                }
            }
            for i in 0..2 {
                for j in 0..2 {
                    t[i][j] = c[i][j] % MOD;
                }
            }
        }
        let mut c = [[0, 0], [0, 0]];
        for i in 0..2 {
            for j in 0..2 {
                for k in 0..2 {
                    c[i][j] += s[i][k] * s[k][j];
                }
            }
        }
        for i in 0..2 {
            for j in 0..2 {
                s[i][j] = c[i][j] % MOD;
            }
        }
        n >>= 1;
    }
    println!("{}", t[1][0]);
}

fn main() {
    run();
}
0