Skip to content

Commit

Permalink
multitestcase
Browse files Browse the repository at this point in the history
  • Loading branch information
maspypy committed Nov 2, 2023
1 parent 62a42fa commit 97eb143
Show file tree
Hide file tree
Showing 12 changed files with 83 additions and 62 deletions.
5 changes: 5 additions & 0 deletions math/factorial/gen/example_00.in
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
5
0
5
100
1234567
998244352
1 change: 0 additions & 1 deletion math/factorial/gen/example_01.in

This file was deleted.

1 change: 0 additions & 1 deletion math/factorial/gen/example_02.in

This file was deleted.

8 changes: 6 additions & 2 deletions math/factorial/gen/near_half.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@ int main(int, char* argv[]) {
long long seed = atoll(argv[1]);
auto gen = Random(seed);

int N = gen.uniform<int>(0.45 * MOD, 0.55 * MOD);
printf("%d\n", N);
int T = T_MAX;
printf("%d\n", T);
for (int t = 0; t < T; ++t) {
int N = gen.uniform<int>(0.45 * MOD, 0.55 * MOD);
printf("%d\n", N);
}
return 0;
}
8 changes: 6 additions & 2 deletions math/factorial/gen/near_max.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@ int main(int, char* argv[]) {
long long seed = atoll(argv[1]);
auto gen = Random(seed);

int N = gen.uniform<int>(0.95 * MOD, MOD - 1);
printf("%d\n", N);
int T = T_MAX;
printf("%d\n", T);
for (int t = 0; t < T; ++t) {
int N = gen.uniform<int>(0.95 * MOD, MOD - 1);
printf("%d\n", N);
}
return 0;
}
8 changes: 6 additions & 2 deletions math/factorial/gen/random.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@ int main(int, char* argv[]) {
long long seed = atoll(argv[1]);
auto gen = Random(seed);

int N = gen.uniform<int>(0, MOD - 1);
printf("%d\n", N);
int T = T_MAX;
printf("%d\n", T);
for (int t = 0; t < T; ++t) {
int N = gen.uniform<int>(0, MOD - 1);
printf("%d\n", N);
}
return 0;
}
48 changes: 14 additions & 34 deletions math/factorial/hash.json
Original file line number Diff line number Diff line change
@@ -1,36 +1,16 @@
{
"example_00.in": "9a271f2a916b0b6ee6cecb2426f0b3206ef074578be55d9bc94f6f3fe3ab86aa",
"example_00.out": "6b86b273ff34fce19d6b804eff5a3f5747ada4eaa22f1d49c01e52ddb7875b4b",
"example_01.in": "eea8254c7500ba3de996aa8ad6af399183f04e17d4a8102fde539dbc93a90012",
"example_01.out": "54a9294060a94f5166e0902704b34c0ddf9e913148e80e2224213ff4c6665a99",
"example_02.in": "d94b5d5e2010ceb1f753093c4b1111b0c411837daf56c8415056eb92346a0bcd",
"example_02.out": "0b274a87936f26e505c159427061edb5d54cc742f78ed7cf8c5e8c58c08639f8",
"near_half_00.in": "4d20fea3b1b8f1331ca5c417cc2fe9829dad91921dd6783810b1d2f1ad97db6a",
"near_half_00.out": "db0a34160e386d1388ad3c24a46a2ca0be698e4b3754a88dff16b691f92bf35a",
"near_half_01.in": "5936077669c4ed43c2b811b52586d429b2423f75476729a676770a51cc9bb961",
"near_half_01.out": "7179dadb7caea3c1461a9bcc5ba46e0533273bd1467b0b7589c5b6a510912689",
"near_half_02.in": "db21c9ce914ed36e55404989c0b918c43745f23bac2ac17fd756c74a8807b68c",
"near_half_02.out": "a85975397f8ac5d98d0bf1c7dfd17a8d37bfa039eb7642ec36ec319a347da5b8",
"near_max_00.in": "ca42e336242d5cdee76c8cf0213094783658996772d25f0859d100dbd33e302f",
"near_max_00.out": "963161328cf7fc7937e5e8830bffff9cfb68ba5ed8c4deb3e180c1488e17910c",
"near_max_01.in": "9d9d4a87eef24902715b2518acdafb773c3096eb6a26bfbc4229d16165f9ffc3",
"near_max_01.out": "c859d0646c408f6dfebcced73cc962f1545ebd049faa4182ef2bb41832b5e287",
"near_max_02.in": "ab0c9e20428c77ee2fe37ba96bce43e9d10cfcece467626d4aae3de35c4b80bf",
"near_max_02.out": "9baf06b85dafe7a017d412e554b2fdad3def30ba119c78f862bb1363b7f8a23c",
"random_00.in": "3cfdf017bf8e88510a8d2d670a5736b66267d2e4af13d68a60871013426e0a01",
"random_00.out": "5e22b5482b97861082f608ae4937af5aeaade883e71e7b8e15f237e73a4fd86c",
"random_01.in": "7e6d42e3a77c2d80f2a05fd9e601e1c1a15271717eb454400e510b5ec92ca4fe",
"random_01.out": "81000415cae1b568ce2d3203dc1e68eccd3ce601af791f9eb12b86fcf66c4233",
"random_02.in": "751ae5dea0048ddcce5248cf2334982830420a40ff5cba50790018073d65ebc5",
"random_02.out": "c03fee4d693dba8cb8dd66baf974e5d3c8975dbca7ce2567c048f9642c2e057b",
"random_03.in": "af3f76179322d5f9409d5fc655ae7f5e6ec6a572a0df43e580f552cbea13a9f2",
"random_03.out": "9b4a83229a0593fa3febf4943ebff8e89304a7b9e05385e404a35a4e91752c38",
"random_04.in": "2581a6e5ce00ad8fc8de99c4e6bec594642a729e4668f306e7047b4f29b2cab7",
"random_04.out": "8692bc2cf1ca11b2db337f4077f642e5cdcc44042b1b1899b850c038178b2220",
"random_05.in": "48d53f8ced4a76f9e8a5256816877a715aee9e3c8b75e2ca09789477f129983e",
"random_05.out": "c7730e9c08817d489536d442d3a344405f09c9b63562479241d90485ecb04f01",
"random_06.in": "da95bcd27b9626ef0cda5fd78625b1706e1927f5530f3e138210effcd8a9975b",
"random_06.out": "1315fc99f118eba7116dc7ff4c13515d76859c49438b0f834d2a3767dc4e5411",
"random_07.in": "bcb2ae24fafc8c1c714cb98c83df708cade5c68b3a40919da635ef1f4139560e",
"random_07.out": "045b1dd57d704ccc139564afe0467f6f0335d22214a2585124e8c2e6379dcdc4"
"example_00.in": "180d1bbdde5539dd3a77d325f8940297325665f9f1be249c051dad6aa177200a",
"example_00.out": "c73d2af1573bc3649136764834711acaf148eb3588cc639d8bf5a57da9bdd867",
"near_half_00.in": "b9b509e96007f2595f9a1845c56544b107a20794261c0a3913056ebc1c472d48",
"near_half_00.out": "09c498ab37ca56ec5d94ca104802a0a8fbc78539941f994880463e874cb5e266",
"near_half_01.in": "78c59f15afe18136e693628e08aa54d462218ac825d29667c75f5d0e6044babc",
"near_half_01.out": "0d58b0459853ec01a08a006ee4f2288c2304264e5551b3a0d65b93dfe111620b",
"near_max_00.in": "da530850d58cc2e3e79f6104dc0af91b76a0ec7d61fc5120b4487f2a94312d6f",
"near_max_00.out": "06f27a007c8c14ad2cb868844bd5a5e94346dc144ee51b6446a1b684a104902f",
"near_max_01.in": "2d4f31d5ddec6a701ed69d204aaa8c49439066f4d675fd99774795757358dc3c",
"near_max_01.out": "3655b1fb1215b40a9c762042096ef89af95e7aa94da5ca63b7daf72263c023a1",
"random_00.in": "ef2dc732889096480a438e542b5dc79018083e8771651ef8ffa37b0fd1f6c246",
"random_00.out": "65ac0924d4ca6ff146997bc802a42aec719d48cc8556127fc2f5d514efaef047",
"random_01.in": "0842027f68881d70d3376224a68b92f9e19f13840ef9d573acdba3c85d1fc1d0",
"random_01.out": "bd08bbc7d8dd2d279da20ce0ba42d99198728e7b3faccc03ab24c4d5576066f1"
}
11 changes: 6 additions & 5 deletions math/factorial/info.toml
Original file line number Diff line number Diff line change
@@ -1,24 +1,25 @@
title = 'Factorial'
timelimit = 5.0
timelimit = 10.0
forum = "https://github.com/yosupo06/library-checker-problems/issues/128"

[[tests]]
name = "example.in"
number = 3
number = 1
[[tests]]
name = "random.cpp"
number = 8
number = 2
[[tests]]
name = "near_max.cpp"
number = 3
number = 2
[[tests]]
name = "near_half.cpp"
number = 3
number = 2

[[solutions]]
name = "naive.cpp"
wrong = false


[params]
T_MAX = 5
MOD = 998244353
6 changes: 4 additions & 2 deletions math/factorial/sol/correct.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -635,10 +635,12 @@ void solve() {
scanf("%d", &N);
vc<mint> f = {1, 1};
mint b = prefix_product_of_poly(f, N);
printf("%d", b.val);
printf("%d\n", b.val);
}

signed main() {
solve();
int T;
scanf("%d", &T);
for (int t = 0; t < T; ++t) solve();
return 0;
}
26 changes: 21 additions & 5 deletions math/factorial/sol/naive.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,29 @@ constexpr int mod = 998244353;
void solve() {
int N;
scanf("%d", &N);

long long ans = 1;
for (int n = 1; n <= N; ++n) ans = ans * n % mod;
printf("%lld", ans);
if (N < mod / 2) {
long long x = 1;
for (int n = 1; n <= N; ++n) x = x * n % mod;
printf("%lld\n", x);
} else {
long long x = mod - 1; // (mod-1)!
long long y = 1;
for (int n = N + 1; n <= mod - 1; ++n) { y = y * n % mod; }
// x / y
// xy^{mod-2}
long long n = mod - 2;
while (n) {
if (n & 1) x = x * y % mod;
y = y * y % mod;
n /= 2;
}
printf("%lld\n", x);
}
}

signed main() {
solve();
int T;
scanf("%d", &T);
for (int t = 0; t < T; ++t) solve();
return 0;
}
17 changes: 10 additions & 7 deletions math/factorial/task.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,37 +2,40 @@

@{lang.en}

This problem has $T$ cases.

Given a non-negative integer $N$. Print $N!$ modulo $@{param.MOD}$.

@{lang.ja}

この問題は $T$ ケースあります.
非負整数 $N$ が与えられます.$N!$ を $@{param.MOD}$ で割った余りを出力してください.

@{lang.end}

## @{keyword.constraints}

- $1\leq T\leq 5$
- $0 \leq N < @{param.MOD}$

## @{keyword.input}

```
$N$
$T$
$N_1$
$\vdots$
$N_T$
```

## @{keyword.output}
@{lang.en}
Given a non-negative integer $N$. Print $N!$ modulo $@{param.MOD}$.
Print $N!$ modulo $@{param.MOD}$.

@{lang.ja}

非負整数 $N$ が与えられます.$N!$ を $@{param.MOD}$ で割った余りを出力してください.
$N!$ を $@{param.MOD}$ で割った余りを出力してください.
@{lang.end}

## @{keyword.sample}

@{example.example_00}

@{example.example_01}

@{example.example_02}
6 changes: 5 additions & 1 deletion math/factorial/verifier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,12 @@

int main() {
registerValidation();
inf.readLong(0, MOD - 1);
int T = inf.readInt(1, T_MAX);
inf.readChar('\n');
for (int t = 0; t < T; ++t) {
inf.readLong(0, MOD - 1);
inf.readChar('\n');
}
inf.readEof();
return 0;
}

0 comments on commit 97eb143

Please sign in to comment.