結果

問題 No.303 割れません
コンテスト
ユーザー ゴリポン先生
提出日時 2026-08-21 17:06:23
言語 D
(dmd 2.112.0)
コンパイル:
dmd -fPIE -m64 -w -wi -O -release -inline -I/opt/dmd/src/druntime/import/ -I/opt/dmd/src/phobos -L-L/opt/dmd/linux/lib64/ -fPIC _filename_
実行:
./Main
結果
TLE  
実行時間 -
コード長 690 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 3,567 ms
コンパイル使用メモリ 190,332 KB
実行使用メモリ 14,480 KB
最終ジャッジ日時 2026-08-21 17:06:52
合計ジャッジ時間 21,294 ms
ジャッジサーバーID
(参考情報)
judge1_0 / judge3_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 1 TLE * 1 -- * 12
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

module main;
// https://yukicoder.me/problems/no/303/editorial より
// 数え上げ、多倍長整数、フィボナッチ数
import std;

BigInt fib(int n)
{
	BigInt a = 1, a1, b = 1, b1, c = 0, c1, x = 1, x1, y = 0, y1;
	--n;
	while (n) {
		if (n & 1) {
			x1 = x; y1 = y;
			x = a * x1 + b * y1; y = b * x1 + c * y1;
		}
		n >>= 1;
		a1 = a; b1 = b; c1 = c;
		a = a1 * a1 + b1 * b1;
		b = b1 * (a1 + c1);
		c = b1 * b1 + c1 * c1;
	}
	return x;
}

void main()
{
	// 入力
	int L = readln.chomp.to!int;
	// 答えの計算と出力
	if (L == 2) {
		writeln(3);
		writeln("INF");
		return;
	}
	writeln(L);
	if (L % 2 == 1)
		writeln(fib(L));
	else
		writeln(fib(L) - fib(L / 2) ^^ 2);
}
0