結果

問題 No.8048 Order and Harmony
ユーザー betrue12betrue12
提出日時 2019-04-01 21:50:54
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
TLE  
実行時間 -
コード長 715 bytes
コンパイル時間 1,414 ms
コンパイル使用メモリ 166,416 KB
実行使用メモリ 10,496 KB
最終ジャッジ日時 2024-11-26 22:26:40
合計ジャッジ時間 61,827 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 43 TLE * 18
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

const int64_t MOD = 1e9+7;

int64_t extgcd(int64_t a, int64_t b, int64_t& x, int64_t& y){
    int64_t d = a;
    if(b != 0){
        d = extgcd(b, a%b, y, x);
        y -= (a/b) * x;
    }else{
        x = 1; y = 0;
    }
    return d;
}

int64_t inv_mod(int64_t a){
    int64_t x, y;
    extgcd(a, MOD, x, y);
    return (MOD + x%MOD) % MOD;
}

int main(){
    int K;
    cin >> K;
    if(K%2){
        cout << 0 << endl;
        return 0;
    }

    int64_t ans = 1;
    for(int i=1; i<=K/2; i++){
        ans = ans * i % MOD;
    }
    ans = inv_mod(ans);
    for(int i=K/2+1; i<=K; i++){
        ans = ans * i % MOD;
    }
    cout << ans << endl;
    return 0;
}
0