結果

問題 No.534 フィボナッチフィボナッチ数
ユーザー takeya_okinotakeya_okino
提出日時 2017-06-23 23:53:40
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,427 bytes
コンパイル時間 2,257 ms
コンパイル使用メモリ 77,224 KB
実行使用メモリ 56,224 KB
最終ジャッジ日時 2024-04-14 06:36:23
合計ジャッジ時間 9,368 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 121 ms
53,008 KB
testcase_01 AC 133 ms
54,224 KB
testcase_02 AC 134 ms
53,964 KB
testcase_03 AC 135 ms
54,096 KB
testcase_04 AC 134 ms
54,228 KB
testcase_05 AC 134 ms
54,240 KB
testcase_06 AC 138 ms
54,048 KB
testcase_07 AC 135 ms
54,288 KB
testcase_08 AC 138 ms
54,188 KB
testcase_09 AC 135 ms
54,152 KB
testcase_10 AC 134 ms
54,020 KB
testcase_11 AC 132 ms
54,256 KB
testcase_12 AC 133 ms
53,976 KB
testcase_13 AC 137 ms
54,216 KB
testcase_14 AC 136 ms
54,296 KB
testcase_15 AC 134 ms
54,144 KB
testcase_16 AC 137 ms
54,316 KB
testcase_17 AC 135 ms
54,032 KB
testcase_18 AC 134 ms
54,212 KB
testcase_19 AC 137 ms
54,276 KB
testcase_20 AC 137 ms
53,788 KB
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
testcase_41 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
  static long MOD = (long)Math.pow(10, 9) + 7; 
  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);
    long t = f[1][0];
    long[][] ans = func(d, t);
    long anse = ans[1][0];
    System.out.println(anse);
  }

  public static long[][] func(long[][] a, long x) {
    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);
    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