結果

問題 No.502 階乗を計算するだけ
ユーザー 遭難者
提出日時 2022-07-12 14:10:48
言語 C++17(gcc12)
(gcc 12.3.0 + boost 1.87.0)
結果
TLE  
実行時間 -
コード長 1,329 bytes
コンパイル時間 19,256 ms
コンパイル使用メモリ 241,376 KB
最終ジャッジ日時 2025-01-30 06:44:02
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 43 TLE * 9
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <stdio.h>
#include <math.h>
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <stack>
#include <numeric>
#include <algorithm>
using namespace std;
using ll = long long;
#include <atcoder/all>
using namespace atcoder;
using mint = modint1000000007;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define ALL(a) (a).begin(), (a).end()
void chmin(int &a, int b)
{
    if (a > b)
        a = b;
}
void chmax(int &a, int b)
{
    if (a < b)
        a = b;
}
mint p(mint a, ll b)
{
    if (b == 0)
        return 1LL;
    if (b & 1)
        return a * p(a, b - 1);
    return p(a * a, b >> 1);
}
ll cnt = 0;
mint f(ll n)
{
    if (n <= 1)
        return 1LL;
    ll m = n >> 1;
    mint ans = f(m);
    if (n & 1)
        ans *= n--;
    for (int i = 3; i < n; i += 2)
        ans *= i;
    cnt += m;
    return ans;
}
int main()
{
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    ll n;
    cin >> n;
    const ll mod = 1e9 + 7;
    if (n >= mod)
    {
        cout << 0 << '\n';
        return 0;
    }
    mint ans = f(n);
    cnt %= mod - 1;
    ans *= p(2 , cnt);
    cout << ans.val() << '\n';
    return 0;
}
0