結果

問題 No.2156 ぞい文字列
ユーザー pengin_2000pengin_2000
提出日時 2022-12-09 22:39:07
言語 C
(gcc 13.3.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,229 bytes
コンパイル時間 325 ms
コンパイル使用メモリ 30,208 KB
実行使用メモリ 6,824 KB
最終ジャッジ日時 2024-10-14 22:32:10
合計ジャッジ時間 1,027 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 16
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<stdio.h>
long long int a[2][2];
long long int res[2][2];
void modpow(long long int n, long long int p)
{
	res[0][0] = 1; res[0][1] = 0;
	res[1][0] = 0; res[1][1] = 1;
	int f[2][2];
	for (; n > 0; n /= 2)
	{
		if (n % 2 > 0)
		{
			f[0][0] = a[0][0] * res[0][0] % p + a[0][1] * res[1][0] % p;
			f[0][1] = a[0][0] * res[0][1] % p + a[0][1] * res[1][1] % p;
			f[1][0] = a[1][0] * res[0][0] % p + a[1][1] * res[1][0] % p;
			f[1][1] = a[1][0] * res[0][1] % p + a[1][1] * res[1][1] % p;
			res[0][0] = f[0][0] % p;
			res[0][1] = f[0][1] % p;
			res[1][0] = f[1][0] % p;
			res[1][1] = f[1][1] % p;
		}
		f[0][0] = a[0][0] * a[0][0] % p + a[0][1] * a[1][0] % p;
		f[0][1] = a[0][0] * a[0][1] % p + a[0][1] * a[1][1] % p;
		f[1][0] = a[1][0] * a[0][0] % p + a[1][1] * a[1][0] % p;
		f[1][1] = a[1][0] * a[0][1] % p + a[1][1] * a[1][1] % p;
		a[0][0] = f[0][0] % p;
		a[0][1] = f[0][1] % p;
		a[1][0] = f[1][0] % p;
		a[1][1] = f[1][1] % p;
	}
	return;
}
int main()
{
	long long int n;
	scanf("%lld", &n);
	const long long int p = 998244353;
	a[0][0] = 1; a[0][1] = 1;
	a[1][0] = 1; a[1][1] = 0;
	modpow(n - 1, p);
	long long int ans = res[0][0] + res[1][0] - 1;
	ans = (ans % p + p) % p;
	printf("%lld\n", ans);
	return 0;
}
0