結果

問題 No.554 recurrence formula
ユーザー tentententen
提出日時 2020-09-07 23:48:33
言語 Java21
(openjdk 21)
結果
AC  
実行時間 137 ms / 2,000 ms
コード長 645 bytes
コンパイル時間 4,367 ms
コンパイル使用メモリ 71,220 KB
実行使用メモリ 55,864 KB
最終ジャッジ日時 2023-08-19 17:20:40
合計ジャッジ時間 6,496 ms
ジャッジサーバーID
(参考情報)
judge10 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 128 ms
55,776 KB
testcase_01 AC 128 ms
55,480 KB
testcase_02 AC 130 ms
55,604 KB
testcase_03 AC 128 ms
55,628 KB
testcase_04 AC 129 ms
55,504 KB
testcase_05 AC 128 ms
55,616 KB
testcase_06 AC 127 ms
55,700 KB
testcase_07 AC 128 ms
55,412 KB
testcase_08 AC 130 ms
55,692 KB
testcase_09 AC 133 ms
55,624 KB
testcase_10 AC 129 ms
55,340 KB
testcase_11 AC 130 ms
55,864 KB
testcase_12 AC 130 ms
55,736 KB
testcase_13 AC 128 ms
55,336 KB
testcase_14 AC 129 ms
55,768 KB
testcase_15 AC 132 ms
55,732 KB
testcase_16 AC 129 ms
55,660 KB
testcase_17 AC 128 ms
55,564 KB
testcase_18 AC 127 ms
55,372 KB
testcase_19 AC 133 ms
55,528 KB
testcase_20 AC 137 ms
55,676 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