結果

問題 No.554 recurrence formula
ユーザー kohaku_kohakukohaku_kohaku
提出日時 2017-08-12 20:52:11
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 686 bytes
コンパイル時間 2,365 ms
コンパイル使用メモリ 77,424 KB
実行使用メモリ 56,164 KB
最終ジャッジ日時 2024-04-21 07:18:19
合計ジャッジ時間 6,144 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 138 ms
40,940 KB
testcase_02 AC 127 ms
40,844 KB
testcase_03 AC 136 ms
41,184 KB
testcase_04 AC 132 ms
40,856 KB
testcase_05 AC 143 ms
40,976 KB
testcase_06 AC 137 ms
41,016 KB
testcase_07 AC 149 ms
41,032 KB
testcase_08 AC 141 ms
41,268 KB
testcase_09 AC 142 ms
40,972 KB
testcase_10 AC 139 ms
40,956 KB
testcase_11 AC 153 ms
41,264 KB
testcase_12 AC 151 ms
41,108 KB
testcase_13 AC 155 ms
41,364 KB
testcase_14 AC 151 ms
40,952 KB
testcase_15 AC 146 ms
41,008 KB
testcase_16 AC 147 ms
41,072 KB
testcase_17 AC 148 ms
40,848 KB
testcase_18 AC 145 ms
41,048 KB
testcase_19 AC 152 ms
41,264 KB
testcase_20 AC 151 ms
40,868 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        long mod = (long)(Math.pow(10,9))+7;
        long odd = 1;
        long even = 2;
        for(int i=3; i<N; i++){
            long tmp=0;
            if(i%2==0){
                tmp = odd*i;
                even += tmp;
                even %= mod;
            }else{
                tmp = even*i;
                odd += tmp;
                odd %= mod;
            }
        }
        if(N%2==0){
            System.out.println(odd*N%mod);
        }else{
            System.out.println(even*N%mod);
        }
    }
}
0