結果
| 問題 |
No.502 階乗を計算するだけ
|
| コンテスト | |
| ユーザー |
まいん-
|
| 提出日時 | 2017-04-07 23:51:02 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 256 ms / 1,000 ms |
| コード長 | 1,928 bytes |
| コンパイル時間 | 1,121 ms |
| コンパイル使用メモリ | 90,024 KB |
| 実行使用メモリ | 6,948 KB |
| 最終ジャッジ日時 | 2024-07-16 03:23:06 |
| 合計ジャッジ時間 | 3,449 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 52 |
ソースコード
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <stack>
#include <queue>
#include <functional>
#include <algorithm>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <vector>
#include <array>
#include <tuple>
#include <utility>
#include <numeric>
#include <iomanip>
#include <cctype>
#include <cmath>
#include <assert.h>
#include <cstdlib>
#include <list>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using PII = pair<int, int>;
using PLL = pair<ll, ll>;
template<typename T1, typename T2> ostream& operator<<(ostream& s, const pair<T1, T2>& p) {
return s << "(" << p.first << ", " << p.second << ")";
}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
s << "[";
for (int i = 0; i < v.size(); i++) s << (i == 0 ? "" : ", ") << v[i];
s << "]";
return s;
}
#define ALL(a) (a).begin(), (a).end()
const ll MOD = 1000 * 1000 * 1000 + 7;
const ll SIZE = 50000000;
ll bucket[30] = {
664720426,
513130043,
845183989,
889311046,
297511867,
341295439,
948482493,
451428770,
249964821,
688320104,
641980953,
824712048,
809640425,
987826843,
682842592,
490277708,
856048785,
25069543,
264355931,
859885879,
999994967,
1,
1,
1,
1,
1,
1,
1,
1,
1
};
int main() {
ll n;
cin >> n;
if (n >= MOD) {
cout << 0 << endl;
return 0;
}
if (n == MOD - 1) {
cout << MOD - 1 << endl;
return 0;
}
ll x = 1;
for (ll b_i = 0; b_i < 30; b_i++) {
if (n >= (b_i + 1) * SIZE) {
x = (x * bucket[b_i]) % MOD;
continue;
}
for (ll m = max(1LL, b_i * SIZE); m <= n; m++) {
x = (x * m) % MOD;
}
break;
}
cout << x << endl;
return 0;
}
まいん-