結果

問題 No.554 recurrence formula
ユーザー tentententen
提出日時 2020-09-07 23:48:33
言語 Java21
(openjdk 21)
結果
AC  
実行時間 126 ms / 2,000 ms
コード長 645 bytes
コンパイル時間 1,892 ms
コンパイル使用メモリ 74,220 KB
実行使用メモリ 41,408 KB
最終ジャッジ日時 2024-05-07 00:21:08
合計ジャッジ時間 4,957 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 113 ms
40,936 KB
testcase_01 AC 111 ms
41,108 KB
testcase_02 AC 107 ms
40,716 KB
testcase_03 AC 101 ms
39,712 KB
testcase_04 AC 103 ms
39,696 KB
testcase_05 AC 114 ms
41,328 KB
testcase_06 AC 116 ms
41,020 KB
testcase_07 AC 112 ms
41,000 KB
testcase_08 AC 101 ms
39,660 KB
testcase_09 AC 109 ms
41,140 KB
testcase_10 AC 108 ms
41,288 KB
testcase_11 AC 112 ms
40,804 KB
testcase_12 AC 113 ms
41,112 KB
testcase_13 AC 100 ms
39,744 KB
testcase_14 AC 106 ms
40,020 KB
testcase_15 AC 111 ms
40,840 KB
testcase_16 AC 100 ms
40,160 KB
testcase_17 AC 100 ms
39,940 KB
testcase_18 AC 106 ms
39,644 KB
testcase_19 AC 126 ms
41,408 KB
testcase_20 AC 116 ms
41,140 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
    static final int MOD = 1000000007;
	public static void main (String[] args) {
    	Scanner sc = new Scanner(System.in);
    	int n = sc.nextInt();
    	if (n == 1) {
    	    System.out.println(1);
    	    return;
    	}
    	long evTotal = 0;
    	long odTotal = 1;
    	long x = 0;
    	for (int i = 2; i <= n; i++) {
    	    if (i % 2 == 0) {
    	        x = odTotal * i % MOD;
    	        evTotal += x;
    	        evTotal %= MOD;
    	    } else {
    	        x = evTotal * i % MOD;
    	        odTotal += x;
    	        odTotal %= MOD;
    	    }
    	}
    	System.out.println(x);
	}
}
0