結果

問題 No.502 階乗を計算するだけ
ユーザー imulanimulan
提出日時 2017-04-12 00:44:29
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 165 ms / 1,000 ms
コード長 1,187 bytes
コンパイル時間 1,500 ms
コンパイル使用メモリ 166,132 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-25 11:20:41
合計ジャッジ時間 4,352 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 AC 1 ms
4,376 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 1 ms
4,376 KB
testcase_18 AC 2 ms
4,376 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 2 ms
4,380 KB
testcase_22 AC 7 ms
4,376 KB
testcase_23 AC 3 ms
4,380 KB
testcase_24 AC 5 ms
4,376 KB
testcase_25 AC 2 ms
4,380 KB
testcase_26 AC 3 ms
4,380 KB
testcase_27 AC 3 ms
4,380 KB
testcase_28 AC 4 ms
4,376 KB
testcase_29 AC 3 ms
4,376 KB
testcase_30 AC 7 ms
4,376 KB
testcase_31 AC 4 ms
4,376 KB
testcase_32 AC 35 ms
4,376 KB
testcase_33 AC 165 ms
4,376 KB
testcase_34 AC 106 ms
4,380 KB
testcase_35 AC 110 ms
4,376 KB
testcase_36 AC 84 ms
4,380 KB
testcase_37 AC 55 ms
4,380 KB
testcase_38 AC 24 ms
4,380 KB
testcase_39 AC 103 ms
4,376 KB
testcase_40 AC 64 ms
4,376 KB
testcase_41 AC 56 ms
4,380 KB
testcase_42 AC 2 ms
4,376 KB
testcase_43 AC 1 ms
4,376 KB
testcase_44 AC 1 ms
4,380 KB
testcase_45 AC 1 ms
4,380 KB
testcase_46 AC 1 ms
4,376 KB
testcase_47 AC 2 ms
4,376 KB
testcase_48 AC 1 ms
4,376 KB
testcase_49 AC 1 ms
4,380 KB
testcase_50 AC 2 ms
4,380 KB
testcase_51 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

typedef long long ll;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define each(itr,c) for(__typeof(c.begin()) itr=c.begin(); itr!=c.end(); ++itr)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second

const ll mod=1e9+7;

ll mod_fact(ll n)
{
    ll ret=1;
    for(ll i=2; i<=n; ++i)
    {
        (ret*=i)%=mod;
        if(i%30000000==0) printf("%lld,", ret);
    }
    printf("\n");
    return ret;
}

ll solve(ll n)
{
    if(n>=mod) return 0;

    vector<ll> v({1,76479948,27368307,888050723,661224977,261384175,547665832,724691727,136026497,217544623,668123525,522049725,189239124,917084264,358655417,462639908,99199382,97830135,141827977,811575797,724464507,456152084,769795511,825871994,852304035,217598709,624500515,423951674,814362881,256473217,586445753,778983779,965785236,847549272});

    ll ret=1;
    int idx=0;
    while((idx+1LL)*30000000<=n) ++idx;

    (ret*=v[idx])%=mod;
    ll start = idx*30000000LL;
    for(ll i=start+1; i<=n; ++i) (ret*=i)%=mod;
    return ret;
}

int main()
{
    // mod_fact(mod-1);
    ll n;
    cin >>n;
    cout << solve(n) << endl;
    return 0;
}
0