結果

問題 No.303 割れません
ユーザー koba-e964koba-e964
提出日時 2016-12-09 22:14:12
言語 Java21
(openjdk 21)
結果
AC  
実行時間 4,589 ms / 10,000 ms
コード長 1,033 bytes
コンパイル時間 3,317 ms
コンパイル使用メモリ 74,476 KB
実行使用メモリ 118,736 KB
最終ジャッジ日時 2023-08-19 06:16:33
合計ジャッジ時間 42,787 ms
ジャッジサーバーID
(参考情報)
judge9 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 118 ms
55,932 KB
testcase_01 AC 110 ms
55,500 KB
testcase_02 AC 110 ms
56,072 KB
testcase_03 AC 1,597 ms
86,836 KB
testcase_04 AC 4,551 ms
118,280 KB
testcase_05 AC 4,589 ms
118,044 KB
testcase_06 AC 4,547 ms
118,736 KB
testcase_07 AC 3,237 ms
112,228 KB
testcase_08 AC 3,347 ms
113,224 KB
testcase_09 AC 3,306 ms
112,076 KB
testcase_10 AC 107 ms
55,848 KB
testcase_11 AC 4,282 ms
113,616 KB
testcase_12 AC 3,400 ms
112,944 KB
testcase_13 AC 2,188 ms
82,548 KB
testcase_14 AC 1,232 ms
80,920 KB
testcase_15 AC 1,329 ms
94,560 KB
testcase_16 AC 117 ms
55,888 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

class Main {
    public static BigInteger fib(int l) {
	BigInteger x = ONE; // sum
	BigInteger y = ZERO;
	BigInteger z = ZERO; // cur
	BigInteger w = ONE;
	int e = l + 1;
	while (e > 0) {
	    if (e % 2 == 1) {
		BigInteger tmp = y.multiply(w);
		BigInteger newx = x.multiply(z).add(tmp);
		BigInteger newy = x.multiply(w).add(y.multiply(z)).add(tmp);
		x = newx;
		y = newy;
	    }
	    BigInteger tmp = w.multiply(w);
	    BigInteger newz = z.multiply(z).add(tmp);
	    BigInteger neww = z.multiply(w).shiftLeft(1).add(tmp);
	    z = newz;
	    w = neww;
	    e /= 2;
	}
	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