結果

問題 No.554 recurrence formula
ユーザー aaaaasatoriaaaaasatori
提出日時 2018-02-24 18:39:11
言語 Java21
(openjdk 21)
結果
AC  
実行時間 139 ms / 2,000 ms
コード長 482 bytes
コンパイル時間 3,466 ms
コンパイル使用メモリ 74,436 KB
実行使用メモリ 42,340 KB
最終ジャッジ日時 2024-04-23 04:46:07
合計ジャッジ時間 7,244 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 130 ms
41,412 KB
testcase_01 AC 134 ms
41,540 KB
testcase_02 AC 131 ms
41,128 KB
testcase_03 AC 131 ms
41,312 KB
testcase_04 AC 131 ms
41,616 KB
testcase_05 AC 129 ms
41,256 KB
testcase_06 AC 130 ms
41,728 KB
testcase_07 AC 134 ms
41,596 KB
testcase_08 AC 131 ms
41,804 KB
testcase_09 AC 120 ms
41,408 KB
testcase_10 AC 129 ms
41,108 KB
testcase_11 AC 133 ms
41,288 KB
testcase_12 AC 129 ms
41,380 KB
testcase_13 AC 132 ms
41,508 KB
testcase_14 AC 136 ms
41,444 KB
testcase_15 AC 131 ms
41,804 KB
testcase_16 AC 131 ms
41,576 KB
testcase_17 AC 131 ms
41,572 KB
testcase_18 AC 134 ms
41,240 KB
testcase_19 AC 138 ms
41,976 KB
testcase_20 AC 139 ms
42,340 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;

public class No554 {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		final long mod = 1000000007;
		int n = sc.nextInt();
		long a[] = new long[n+1];
		a[1] = 1;
		long sumeven = 0;
		long sumodd = 0;
		for(int i = 2;i <= n;i++) {
			if(i % 2 == 0) {
				sumeven += a[i-1] % mod;
				a[i] = i * sumeven % mod;
			}else {
				sumodd += a[i-1] % mod;
				a[i] = i * sumodd % mod;
			}
		}
		System.out.println(a[n]);
	}
}
0