結果

問題 No.303 割れません
ユーザー koba-e964
提出日時 2016-12-09 22:06:51
言語 Java
(openjdk 23)
結果
TLE  
実行時間 -
コード長 646 bytes
コンパイル時間 3,029 ms
コンパイル使用メモリ 74,668 KB
実行使用メモリ 88,060 KB
最終ジャッジ日時 2024-11-28 20:07:47
合計ジャッジ時間 136,114 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 2 TLE * 12
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;
import java.math.*;
import static java.math.BigInteger.*;

class Main {
    public static BigInteger fib(int l) {
	BigInteger x = ZERO;
	BigInteger y = ONE;
	for (int i = 0; i < l; ++i) {
	    BigInteger z = x.add(y);
	    x = y;
	    y = z;
	}
	return x;
    }
    public static void main(String[] args) {
	Scanner sc = new Scanner(System.in);
	int l = sc.nextInt();
	if (l == 2) {
	    System.out.println("3\nINF");
	    return;
	}
	System.out.println(l);
	if (l % 2 == 1) {
	    System.out.println(fib(l));
	} else {
	    BigInteger tmp = fib(l / 2);
	    System.out.println(fib(l).subtract(tmp.multiply(tmp)));
	}
    }
}
0