結果

問題 No.502 階乗を計算するだけ
ユーザー cosnomicosnomi
提出日時 2019-11-16 22:46:20
言語 C++11
(gcc 13.3.0)
結果
TLE  
実行時間 -
コード長 707 bytes
コンパイル時間 553 ms
コンパイル使用メモリ 70,260 KB
実行使用メモリ 13,884 KB
最終ジャッジ日時 2024-09-25 05:44:11
合計ジャッジ時間 3,629 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 32 TLE * 1 -- * 19
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <cmath>
#include <iostream>
#include <iomanip>

using namespace std;

int M = 1000000007;

long mod_mul(long a, long b)
{
    return ((a % M) * (b % M)) % M;
}
long mod_factorial(int n)
{
    long res = 1;
    for (int i = 1; i <= n; i++)
    {
        res = mod_mul(res, i);
    }
    // cout << "fact:" << n << " " << res << endl;
    return res;
}
long mod_pow(int n, int m)
{
    if (m == 0)
        return 1;
    else if (m == 1)
        return n % M;
    else if (m % 2 == 0)
    {
        return (long)pow(mod_pow(n, m / 2), 2) % M;
    }
    return (long)mod_mul((mod_pow(n, m - 1)), n);
}

int main() {
    int n;
    cin >> n;
    cout << mod_factorial(n) << endl;
}
0