結果

問題 No.2156 ぞい文字列
ユーザー ixTL255ixTL255
提出日時 2022-12-31 12:41:39
言語 Rust
(1.77.0)
結果
AC  
実行時間 1 ms / 2,000 ms
コード長 662 bytes
コンパイル時間 835 ms
コンパイル使用メモリ 141,192 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-17 13:55:29
合計ジャッジ時間 2,203 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 0 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 0 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 0 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 AC 1 ms
4,376 KB
testcase_16 AC 1 ms
4,376 KB
testcase_17 AC 1 ms
4,380 KB
testcase_18 AC 1 ms
4,376 KB
testcase_19 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

const MOD: i64 = 998244353;

fn mul(a: &[i64; 4], b: &[i64; 4]) -> [i64; 4] {
	let mut c = [0; 4];
	for i in 0..2 {
		for k in 0..2{
			for j in 0..2 {
				c[i*2+j] = (c[i*2+j] + a[i*2+k] * b[k*2+j]) % MOD;
			} 
		}
	}
	c
}

fn pow(mut a: [i64; 4], mut n: i64) -> [i64; 4] {
	let mut b = [1, 0, 0, 1];
	while n > 0 {
		if n & 1 != 0 {
			b = mul(&b, &a);
		}
		a = mul(&a, &a);
		n >>= 1;
	}
	b
}

fn fib_repeat(n: i64) -> i64 {
	let mut a = [1, 1, 1, 0];
	a = pow(a, n);
	a[2]
}

fn main() {
	let mut s = String::new();
	std::io::stdin().read_line(&mut s).ok();
	let n: i64 = s.trim().parse().unwrap();
	let ans = fib_repeat(n +1) - 1;
	println!("{}", ans);
}
0