Skip to content

Commit

Permalink
Merge pull request #1062 from suisen-cp/many_factorials
Browse files Browse the repository at this point in the history
[Add Problem] Many Factorials
  • Loading branch information
NachiaVivias authored Nov 21, 2023
2 parents 281f0b3 + bb5dcc8 commit 521e4a2
Show file tree
Hide file tree
Showing 15 changed files with 5,260 additions and 0 deletions.
62 changes: 62 additions & 0 deletions math/many_factorials/checker.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
// https://github.com/MikeMirzayanov/testlib/blob/master/checkers/wcmp.cpp

// The MIT License (MIT)

// Copyright (c) 2015 Mike Mirzayanov

// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:

// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.

// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.

#include "testlib.h"

using namespace std;

int main(int argc, char * argv[])
{
setName("compare sequences of tokens");
registerTestlibCmd(argc, argv);

int n = 0;
string j, p;

while (!ans.seekEof() && !ouf.seekEof())
{
n++;

ans.readWordTo(j);
ouf.readWordTo(p);

if (j != p)
quitf(_wa, "%d%s words differ - expected: '%s', found: '%s'", n, englishEnding(n).c_str(), compress(j).c_str(), compress(p).c_str());
}

if (ans.seekEof() && ouf.seekEof())
{
if (n == 1)
quitf(_ok, "\"%s\"", compress(j).c_str());
else
quitf(_ok, "%d tokens", n);
}
else
{
if (ans.seekEof())
quitf(_wa, "Participant output contains extra tokens");
else
quitf(_wa, "Unexpected EOF in the participants output");
}
}
6 changes: 6 additions & 0 deletions math/many_factorials/gen/example_00.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
5
0
5
100
1234567
998244352
28 changes: 28 additions & 0 deletions math/many_factorials/gen/many_bits.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#include <cassert>
#include <cstdio>
#include "../params.h"
#include "random.h"

int main(int, char* argv[]) {
long long seed = atoll(argv[1]);
auto gen = Random(seed);

const int k = 12 + atoll(argv[1]);
assert(12 <= k and k <= 16);

auto genN = [&]{
long long N = gen.uniform<long long>(0LL, MOD - 1);
N |= (1LL << (k - 1)) - 1;
N &= ~(1LL << k);
return N;
};

int T = T_MAX;
printf("%d\n", T);
for (int t = 0; t < T; ++t) {
long long N = genN();
while (N >= MOD) N = genN();
printf("%d\n", int(N));
}
return 0;
}
16 changes: 16 additions & 0 deletions math/many_factorials/gen/near_half.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#include <cstdio>
#include "../params.h"
#include "random.h"

int main(int, char* argv[]) {
long long seed = atoll(argv[1]);
auto gen = Random(seed);

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;
}
16 changes: 16 additions & 0 deletions math/many_factorials/gen/near_max.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#include <cstdio>
#include "../params.h"
#include "random.h"

int main(int, char* argv[]) {
long long seed = atoll(argv[1]);
auto gen = Random(seed);

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;
}
16 changes: 16 additions & 0 deletions math/many_factorials/gen/random.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#include <cstdio>
#include "../params.h"
#include "random.h"

int main(int, char* argv[]) {
long long seed = atoll(argv[1]);
auto gen = Random(seed);

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;
}
26 changes: 26 additions & 0 deletions math/many_factorials/hash.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"example_00.in": "180d1bbdde5539dd3a77d325f8940297325665f9f1be249c051dad6aa177200a",
"example_00.out": "c73d2af1573bc3649136764834711acaf148eb3588cc639d8bf5a57da9bdd867",
"many_bits_00.in": "84b58d9f6be78fe31392af21dc7b5a630600b96d334fd022891bdd3022ebc7fa",
"many_bits_00.out": "70288ffd33d765abbb35762d2fb7a7be23e35d220fc2dd3cb7624e47b4e497eb",
"many_bits_01.in": "9b784889fd46b35e69fe0896b9268fafd9769c4973e57f433a7ab0e57e87be9e",
"many_bits_01.out": "42f14b0f5425749f784bb26fef6b1c274c8f655a683b923a767a067956ed1cba",
"many_bits_02.in": "48ca027109bcea7ea92c3aa04647a2c8599a66b8f566244ee1294fdf19a5ee7b",
"many_bits_02.out": "ffd73ff81135267eea061e1bf6a8f86903fa930914f0ce5445670b52278ee038",
"many_bits_03.in": "6e52339fe5d735e3517e0e09948b836a5ded5dac3b0d739ff0cc088aa502e3a5",
"many_bits_03.out": "23ecd30cffd077f597913ef038e41643f521ef43b1ae39fdb0d78edc0cc1c2ae",
"many_bits_04.in": "393fa853bc41241884d15b4f9f5e33de228b90d86b635b7d44174485a3e82354",
"many_bits_04.out": "b6bb238185c1d299bd1722c5e2698c1eab5c2a1cbef8a6096c0354fdce204ef6",
"near_half_00.in": "d0423a7ca307c6628a31f023886ac0aae10f5361c4639c6a2c02178e0fc82e7a",
"near_half_00.out": "07fad11b95a066bf82137992431dc10d822b04b80d7dccfe208dd8958064590b",
"near_half_01.in": "2ace951d5eec4c25991f34c6e45f629a531525b5e759cb437edf11c2c76cc8da",
"near_half_01.out": "bff39021b53b9a4fc0932c812d828bdf5e1edbb0f4d4a1bb0fba5351cecb6526",
"near_max_00.in": "3611521c88cf54f48663098d740efe4c682274e89e4087913013bca9ffb7d193",
"near_max_00.out": "2f0915e4b6a8cb5c1504871b8aa2971f1b3c618182da647a69839b19c9b33635",
"near_max_01.in": "9480c05cca42d3f5a08dd6fe8c587b5f00653f62df71226f5be7a675bc6d6a07",
"near_max_01.out": "2f5f0767d98361d0b8531e54c01d234aa0b3d3526cad44311765398da03236fc",
"random_00.in": "c8456b1dcbf2199d257d6af42625801b161e730ac72a4be64137235b1ad512b0",
"random_00.out": "068644484ece36a994510f58278c524ff6de31c28e465c1b2f73de0839c48b19",
"random_01.in": "c6b89246ae096db718de6046a8518368e3f650f6aaf6d98cf2948d77e9fc9f7a",
"random_01.out": "93df607bcd7f34b676676426dc322110519c293281da98c17d34889e796bc11d"
}
43 changes: 43 additions & 0 deletions math/many_factorials/info.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
title = 'Many Factorials'
timelimit = 10.0
forum = "https://github.com/yosupo06/library-checker-problems/issues/1058"

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

[[solutions]]
name = "correct_log_time_multieval_faster.cpp"
wrong = false
allow_tle = false

[[solutions]]
name = "correct_log_time_multieval.cpp"
wrong = false
allow_tle = false

[[solutions]]
name = "sqrt.cpp"
wrong = false
allow_tle = true

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

[params]
T_MAX = 100000
MOD = 998244353
Loading

0 comments on commit 521e4a2

Please sign in to comment.