結果

問題 No.554 recurrence formula
ユーザー aaaaasatoriaaaaasatori
提出日時 2018-02-24 18:39:11
言語 Java19
(openjdk 21)
結果
AC  
実行時間 129 ms / 2,000 ms
コード長 482 bytes
コンパイル時間 4,490 ms
コンパイル使用メモリ 72,852 KB
実行使用メモリ 56,288 KB
最終ジャッジ日時 2023-08-05 06:40:07
合計ジャッジ時間 7,749 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 120 ms
55,928 KB
testcase_01 AC 121 ms
55,776 KB
testcase_02 AC 121 ms
56,236 KB
testcase_03 AC 120 ms
55,988 KB
testcase_04 AC 120 ms
56,288 KB
testcase_05 AC 120 ms
55,956 KB
testcase_06 AC 120 ms
55,712 KB
testcase_07 AC 120 ms
55,644 KB
testcase_08 AC 123 ms
55,820 KB
testcase_09 AC 122 ms
54,256 KB
testcase_10 AC 123 ms
55,732 KB
testcase_11 AC 125 ms
56,012 KB
testcase_12 AC 123 ms
55,832 KB
testcase_13 AC 124 ms
55,560 KB
testcase_14 AC 125 ms
55,480 KB
testcase_15 AC 125 ms
55,764 KB
testcase_16 AC 125 ms
55,652 KB
testcase_17 AC 124 ms
55,688 KB
testcase_18 AC 122 ms
55,968 KB
testcase_19 AC 129 ms
55,788 KB
testcase_20 AC 127 ms
55,836 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