結果

問題 No.554 recurrence formula
ユーザー kohaku_kohakukohaku_kohaku
提出日時 2017-08-12 20:53:30
言語 Java21
(openjdk 21)
結果
AC  
実行時間 132 ms / 2,000 ms
コード長 745 bytes
コンパイル時間 2,143 ms
コンパイル使用メモリ 74,444 KB
実行使用メモリ 41,372 KB
最終ジャッジ日時 2024-04-21 07:18:27
合計ジャッジ時間 5,950 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 129 ms
41,172 KB
testcase_01 AC 122 ms
40,976 KB
testcase_02 AC 121 ms
40,776 KB
testcase_03 AC 126 ms
41,020 KB
testcase_04 AC 125 ms
41,084 KB
testcase_05 AC 112 ms
40,928 KB
testcase_06 AC 124 ms
41,372 KB
testcase_07 AC 126 ms
41,132 KB
testcase_08 AC 125 ms
41,184 KB
testcase_09 AC 122 ms
41,120 KB
testcase_10 AC 110 ms
40,988 KB
testcase_11 AC 110 ms
40,852 KB
testcase_12 AC 117 ms
40,984 KB
testcase_13 AC 120 ms
40,956 KB
testcase_14 AC 120 ms
40,784 KB
testcase_15 AC 123 ms
41,152 KB
testcase_16 AC 111 ms
40,960 KB
testcase_17 AC 122 ms
41,044 KB
testcase_18 AC 122 ms
41,364 KB
testcase_19 AC 132 ms
40,968 KB
testcase_20 AC 127 ms
41,176 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==1){
            System.out.println(1);
        }else if(N%2==0){
            System.out.println(odd*N%mod);
        }else{
            System.out.println(even*N%mod);
        }
    }
}
0