結果

問題 No.534 フィボナッチフィボナッチ数
ユーザー takeya_okinotakeya_okino
提出日時 2017-06-24 18:40:13
言語 Java21
(openjdk 21)
結果
AC  
実行時間 138 ms / 2,000 ms
コード長 1,508 bytes
コンパイル時間 2,102 ms
コンパイル使用メモリ 77,744 KB
実行使用メモリ 54,456 KB
最終ジャッジ日時 2024-04-14 22:37:51
合計ジャッジ時間 9,098 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 133 ms
54,136 KB
testcase_01 AC 131 ms
54,136 KB
testcase_02 AC 130 ms
54,040 KB
testcase_03 AC 132 ms
53,800 KB
testcase_04 AC 131 ms
54,184 KB
testcase_05 AC 135 ms
54,268 KB
testcase_06 AC 135 ms
54,456 KB
testcase_07 AC 133 ms
54,160 KB
testcase_08 AC 130 ms
54,016 KB
testcase_09 AC 131 ms
54,100 KB
testcase_10 AC 131 ms
54,128 KB
testcase_11 AC 134 ms
54,088 KB
testcase_12 AC 134 ms
54,016 KB
testcase_13 AC 136 ms
54,108 KB
testcase_14 AC 135 ms
54,132 KB
testcase_15 AC 134 ms
54,100 KB
testcase_16 AC 133 ms
53,876 KB
testcase_17 AC 134 ms
54,152 KB
testcase_18 AC 134 ms
54,260 KB
testcase_19 AC 136 ms
54,252 KB
testcase_20 AC 133 ms
53,880 KB
testcase_21 AC 133 ms
54,048 KB
testcase_22 AC 132 ms
54,424 KB
testcase_23 AC 133 ms
54,372 KB
testcase_24 AC 133 ms
53,984 KB
testcase_25 AC 136 ms
54,204 KB
testcase_26 AC 138 ms
54,340 KB
testcase_27 AC 132 ms
53,964 KB
testcase_28 AC 133 ms
54,412 KB
testcase_29 AC 134 ms
53,892 KB
testcase_30 AC 133 ms
54,368 KB
testcase_31 AC 134 ms
54,144 KB
testcase_32 AC 132 ms
54,232 KB
testcase_33 AC 133 ms
54,188 KB
testcase_34 AC 132 ms
54,280 KB
testcase_35 AC 134 ms
54,036 KB
testcase_36 AC 133 ms
54,268 KB
testcase_37 AC 133 ms
54,240 KB
testcase_38 AC 132 ms
54,188 KB
testcase_39 AC 132 ms
54,172 KB
testcase_40 AC 134 ms
54,024 KB
testcase_41 AC 134 ms
54,148 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
  static long MOD1 = (long)Math.pow(10, 9) + 7;
  static long MOD2 = 2 * (long)Math.pow(10, 9) + 16; 
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    long n = sc.nextLong();
    long[][] d = new long[2][2];
    d[0][0] = 1;
    d[0][1] = 1;
    d[1][0] = 1;
    long[][] f = func(d, n, MOD2);
    long t = f[1][0];
    long[][] ans = func(d, t, MOD1);
    long anse = ans[1][0];
    System.out.println(anse);
  }

  public static long[][] func(long[][] a, long x, long mod) {
    if(x == 0) {
      long[][] b = new long[2][2];
      b[0][0] = 1;
      b[1][1] = 1;
      return b;
    }
    long[][] c = func(a, x / 2, mod);
    long[][] d = new long[2][2];
    d[0][0] = (((c[0][0] * c[0][0]) % mod) + ((c[0][1] * c[1][0]) % mod)) % mod;
    d[0][1] = (((c[0][0] * c[0][1]) % mod) + ((c[0][1] * c[1][1]) % mod)) % mod;
    d[1][0] = (((c[1][0] * c[0][0]) % mod) + ((c[1][1] * c[1][0]) % mod)) % mod;
    d[1][1] = (((c[1][0] * c[0][1]) % mod) + ((c[1][1] * c[1][1]) % mod)) % mod;
    if(x % 2 == 0) {
      return d;
    } else {
      long[][] e = new long[2][2];
      e[0][0] = (((a[0][0] * d[0][0]) % mod) + ((a[0][1] * d[1][0]) % mod)) % mod;
      e[0][1] = (((a[0][0] * d[0][1]) % mod) + ((a[0][1] * d[1][1]) % mod)) % mod;
      e[1][0] = (((a[1][0] * d[0][0]) % mod) + ((a[1][1] * d[1][0]) % mod)) % mod;
      e[1][1] = (((a[1][0] * d[0][1]) % mod) + ((a[1][1] * d[1][1]) % mod)) % mod;
      return e;
    }
  }
}
0