結果

問題 No.1126 SUM
ユーザー tentententen
提出日時 2023-02-16 15:46:48
言語 Java21
(openjdk 21)
結果
AC  
実行時間 88 ms / 1,000 ms
コード長 2,365 bytes
コンパイル時間 2,568 ms
コンパイル使用メモリ 85,404 KB
実行使用メモリ 50,908 KB
最終ジャッジ日時 2023-09-25 20:17:28
合計ジャッジ時間 6,043 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 80 ms
50,520 KB
testcase_01 AC 69 ms
50,520 KB
testcase_02 AC 63 ms
48,524 KB
testcase_03 AC 55 ms
50,428 KB
testcase_04 AC 67 ms
50,860 KB
testcase_05 AC 67 ms
50,512 KB
testcase_06 AC 62 ms
50,656 KB
testcase_07 AC 79 ms
50,544 KB
testcase_08 AC 75 ms
50,448 KB
testcase_09 AC 73 ms
50,568 KB
testcase_10 AC 56 ms
50,660 KB
testcase_11 AC 76 ms
50,652 KB
testcase_12 AC 81 ms
48,544 KB
testcase_13 AC 68 ms
50,736 KB
testcase_14 AC 60 ms
50,908 KB
testcase_15 AC 59 ms
50,472 KB
testcase_16 AC 75 ms
50,724 KB
testcase_17 AC 62 ms
50,624 KB
testcase_18 AC 72 ms
50,520 KB
testcase_19 AC 64 ms
50,508 KB
testcase_20 AC 64 ms
50,540 KB
testcase_21 AC 66 ms
50,636 KB
testcase_22 AC 65 ms
50,512 KB
testcase_23 AC 73 ms
50,864 KB
testcase_24 AC 75 ms
50,524 KB
testcase_25 AC 88 ms
50,720 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.*;
import java.util.*;
import java.util.stream.*;

public class Main {
    static final int MOD = 1000000007;
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner();
        int n = sc.nextInt();
        int m = sc.nextInt();
        long factN = fact(n);
        long base = factN;
        long div1 = pow(factN, MOD - 2);
        long div2 = 1;
        long ans = base * div1 % MOD;
        for (int i = 1; i <= m - n; i++) {
            base *= n + i;
            base %= MOD;
            div2 *= i;
            div2 %= MOD;
            ans += base * div1 % MOD * pow(div2, MOD - 2) % MOD;
            ans %= MOD;
        }
        System.out.println(ans);
    }
    
    static long pow(long x, int p) {
        if (p == 0) {
            return 1;
        } else if (p % 2 == 0) {
            return pow(x * x % MOD, p / 2);
        } else {
            return pow(x, p - 1) * x % MOD;
        }
    }
    
    static long fact(int x) {
        long ans = 1;
        for (int i = 2; i <= x; i++) {
            ans *= x;
            ans %= MOD;
        }
        return ans;
    }
}
class Utilities {
    static String arrayToLineString(Object[] arr) {
        return Arrays.stream(arr).map(x -> x.toString()).collect(Collectors.joining("\n"));
    }
    
    static String arrayToLineString(int[] arr) {
        return String.join("\n", Arrays.stream(arr).mapToObj(String::valueOf).toArray(String[]::new));
    }
}
class Scanner {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer st = new StringTokenizer("");
    StringBuilder sb = new StringBuilder();
    
    public Scanner() throws Exception {
        
    }
    
    public int nextInt() throws Exception {
        return Integer.parseInt(next());
    }
    
    public long nextLong() throws Exception {
        return Long.parseLong(next());
    }
    
    public double nextDouble() throws Exception {
        return Double.parseDouble(next());
    }
    
    public int[] nextIntArray() throws Exception {
        return Stream.of(br.readLine().split(" ")).mapToInt(Integer::parseInt).toArray();
    }
    
    public String next() throws Exception {
        while (!st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }
    
}
0