Skip to content

Commit

Permalink
Merge pull request #1069 from suisen-cp/consecutive_terms_of_linear_r…
Browse files Browse the repository at this point in the history
…ecurrent_sequence

Add Problem: Consecutive Terms of Linear Recurrent Sequence
  • Loading branch information
maspypy authored Dec 24, 2023
2 parents 9f88f03 + e176106 commit d036b80
Show file tree
Hide file tree
Showing 17 changed files with 2,752 additions and 0 deletions.
62 changes: 62 additions & 0 deletions math/consecutive_terms_of_linear_recurrent_sequence/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");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
2 5 10
1 1
1 1
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
2 1 4
1 1
0 0
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
4 0 7
1 2 3 4
1 1 0 0
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#include <cstdio>
#include "random.h"
#include "../params.h"

using namespace std;
using ll = long long;

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

long long d = D_MAX;
long long k = K_MAX;
long long m = M_MAX;

printf("%lld %lld %lld\n", d, k, m);

for(int _ = 0; _ < 2; _++) {
for (int i = 0; i < d; i++) {
printf("%d", gen.uniform<int>(0, MOD - 1));
printf(i == d - 1 ? "\n" : " ");
}
}
return 0;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#include <cstdio>
#include "random.h"
#include "../params.h"

using namespace std;
using ll = long long;

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

long long d = 65535 + (seed % 3);
long long k = gen.uniform<long long>(0, K_MAX);
long long m = gen.uniform<long long>(1, M_MAX);

printf("%lld %lld %lld\n", d, k, m);

for(int _ = 0; _ < 2; _++) {
for (int i = 0; i < d; i++) {
printf("%d", gen.uniform<int>(0, MOD - 1));
printf(i == d - 1 ? "\n" : " ");
}
}
return 0;
}
25 changes: 25 additions & 0 deletions math/consecutive_terms_of_linear_recurrent_sequence/gen/random.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#include <cstdio>
#include "random.h"
#include "../params.h"

using namespace std;
using ll = long long;

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

long long d = gen.uniform<int>(1, D_MAX);
long long k = gen.uniform<long long>(0, K_MAX);
long long m = gen.uniform<long long>(1, M_MAX);

printf("%lld %lld %lld\n", d, k, m);

for(int _ = 0; _ < 2; _++) {
for (int i = 0; i < d; i++) {
printf("%d", gen.uniform<int>(0, MOD - 1));
printf(i == d - 1 ? "\n" : " ");
}
}
return 0;
}
25 changes: 25 additions & 0 deletions math/consecutive_terms_of_linear_recurrent_sequence/gen/small.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#include <cstdio>
#include "random.h"
#include "../params.h"

using namespace std;
using ll = long long;

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

long long d = gen.uniform<int>(1, 1000);
long long k = gen.uniform<int>(0, 1000);
long long m = gen.uniform<int>(1, 1000);

printf("%lld %lld %lld\n", d, k, m);

for(int _ = 0; _ < 2; _++) {
for (int i = 0; i < d; i++) {
printf("%d", gen.uniform<int>(0, MOD - 1));
printf(i == d - 1 ? "\n" : " ");
}
}
return 0;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#include <cstdio>
#include "random.h"
#include "../params.h"

using namespace std;
using ll = long long;

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

long long d = gen.uniform<int>(1, 1000);
int trailing_zeros = gen.uniform<int>(1, d);
long long k = gen.uniform<long long>(0, 1000);
long long m = gen.uniform<long long>(1, 1000);

printf("%lld %lld %lld\n", d, k, m);

for (int i = 0; i < d; i++) {
printf("%d", gen.uniform<int>(0, MOD - 1));
printf(i == d - 1 ? "\n" : " ");
}

for (int i = 0; i < d; i++) {
int c_i = 0;
if (i + trailing_zeros < d) {
c_i = gen.uniform<int>(0, MOD - 1);
}
printf("%d", c_i);
printf(i == d - 1 ? "\n" : " ");
}
return 0;
}
28 changes: 28 additions & 0 deletions math/consecutive_terms_of_linear_recurrent_sequence/gen/zero.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#include <cstdio>
#include "random.h"
#include "../params.h"

using namespace std;
using ll = long long;

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

long long d = gen.uniform<int>(1, 1000);
long long k = gen.uniform<long long>(0, 1000);
long long m = gen.uniform<long long>(1, 1000);

printf("%lld %lld %lld\n", d, k, m);

for (int i = 0; i < d; i++) {
printf("%d", gen.uniform<int>(0, MOD - 1));
printf(i == d - 1 ? "\n" : " ");
}

for (int i = 0; i < d; i++) {
printf("%d", 0);
printf(i == d - 1 ? "\n" : " ");
}
return 0;
}
72 changes: 72 additions & 0 deletions math/consecutive_terms_of_linear_recurrent_sequence/hash.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
{
"example_00.in": "e6089bfb9a5d508d468c5e94b11bebbd91be5aecaffb1cfb64a5f2d9d34af031",
"example_00.out": "d1653bb39274cd43ae8632a815b952cc5c7905ec46819d5f9589b888064fa692",
"example_01.in": "b452c6a3cc91f33d2dc93932f21608d9295da5b79db0ab573815b8899c427adb",
"example_01.out": "eef738b788f325c0e59cd7314c5e83e857da6d67ed8bb8784796bff27ca8ed34",
"example_02.in": "43244cd4c118dfd28c43d972b6cd6776a3d4c7916c3fbcfa82329a14a8834d15",
"example_02.out": "af6924d7c8eb7b2962879d2b0020ac1da380d22680289ac98bec796f50206ff1",
"max_random_00.in": "a27a10f9959afed3696b7294e97f540af989c3939dd01eb18dcaf2db8fc39037",
"max_random_00.out": "ba9679502d177d925c61d2c6a8f35f7f16cbb0536fceda092ed95324c4a345de",
"max_random_01.in": "a16b47cd73f7c3e31c18dfeb0c150c37cc54f5ee8f6655148a939ff143d7fd7e",
"max_random_01.out": "874d09a0cfb7dfcad7156b447aa6677acfc3b18a54aaebfb9ac9d40e0d51f6d9",
"max_random_02.in": "7758d58b61165b9af43828ff17c43c48e22a437d3f4e16d9f6b9b3aa2d0cac06",
"max_random_02.out": "9981ef042fbcb5cab3394beafd9b8b25e86c93323e02acb84be3f14fdd474c19",
"near_65536_00.in": "caf7002f17bfcf40c2183e534376da31e926908cc75916bbeb47ed2126743aa6",
"near_65536_00.out": "a7c1c15d738e1d41f43870581e0e8f72fab17cc9c243faec1cd3dfca14e9efa9",
"near_65536_01.in": "fec74707792ac11115da91e90be3a47097e6fa7dd24b4b427ac67d5a36db89e3",
"near_65536_01.out": "59a15689eb29b1573e25a3ff20046c740cc6290de9d22b72217c346198eb2d9e",
"near_65536_02.in": "267eb152e837455b3591fde963e27154105836c1ef037ea53ec2f247e73a7924",
"near_65536_02.out": "b307935451dbc24e5bfa2139d4612d6ba3f5b4fa774734f302af923a4c6f6997",
"random_00.in": "cfa9a0b424a835aea784ee2f7bbc2dc97a2b7795781f175d5756a75a6d3104c4",
"random_00.out": "9c229edd235336b49b84e1a936cb4d6463163499986e3400283e175989208962",
"random_01.in": "d3d999e16039a5f7378bca34ebf45ac47d2fac797908be9c3eb1b037810df669",
"random_01.out": "0955b59907971eca31ede6522311e47340fa76dbb61373e87556fd622f6228bb",
"random_02.in": "7bc695632349d9d68aae03a0e646a99e9cc8fc718ea02062f369e4bd8ba21920",
"random_02.out": "b2fb6660dd7d5b543b8969f688e8bb37817f19042268b07b715b0731fca6d030",
"small_00.in": "1003de1568d5aed45f01167d2d41e04203f0742222ff10f7ced701d37770ead4",
"small_00.out": "e578094d991b32c13c19cb74afd8fa9353c30cfa0733cd9f03a4b06fd165f363",
"small_01.in": "6a7c9f8972ac04c7238886c588c75e1503cdef9e9b901e4d9e037425e6cfd1cd",
"small_01.out": "d3df639ffa8545b006d31d554ce64b0c774c1d6f516401284f96216bef3146dd",
"small_02.in": "743d2d0e9d7b0c57df3c00f5a16ab91df890a3c8a6468e50c402c482ff3a33bb",
"small_02.out": "3efec97531572529f5eee56eadfac6ae0e7bcb3ba40860bb4fab49f3b32cea56",
"small_03.in": "3d9a913dc3471452e70818ad7574f52f6e6878a25245b42004130db069c63410",
"small_03.out": "50cbbe421e507a7af117634f92d3b61c63ae06fab3614ef7a290be6a88ef6479",
"small_04.in": "aa6873acb543d3ffed1fb3623a9486ed14ecc1621fe6f7a5eaa9812717cd0293",
"small_04.out": "9fe7e41e7bb3313c5d042c47e6dbb571892d1a05a0e7f5cf075f6db0745bd48f",
"small_05.in": "b7bf1951ce62204d15c0f1a05f3e2c0c40dc0e2d40400d942dacf61cb47b49b1",
"small_05.out": "96a9ecf5e39a4f13f1048808fc34fe2a9569e46f1f5dbab7b3a84a3460f29375",
"small_06.in": "7077604dd299263bfccb00d16a298fb4c1a788184604c120c9eeff315d166cb4",
"small_06.out": "68fefb0d8fece54fee85aea03976f4be33330e4175a8381f22bb1f8647e8a369",
"small_07.in": "5ab8b92bfa310919fbe57dcb240bfe495b4fef58afcfddd8a4116bb8ed91cfff",
"small_07.out": "c686ab09b2b67ee0e92d85d6aa3da87e9a3cb0db8dd9b737086799c5536f5e59",
"small_08.in": "f659b47205a6a7883fb7bf9330dd0ad13b467e0394fd3e742fe422374e5c0164",
"small_08.out": "e0a159298f7c5b190bf0dd2befa682560d4625cb4d6381028e1e04fe42e854d3",
"small_09.in": "b64864addbfb9d8b9c0059dd1083a6181d5463941a0a1f51f2f8562b65e17f2e",
"small_09.out": "92725cb0f37bdcd51914775b125caaf7416a1390a5efb9e1629a849ab682e504",
"trailing_zeros_00.in": "f9c2d18afaa67bf691c3b0946f7daa245b7af69fed0d6ec3e32bf8b85c7463f1",
"trailing_zeros_00.out": "1797ea27d7d15813355e6b69c2ef6b0fe5d9d08bafa7d5511b7b5694197be47a",
"trailing_zeros_01.in": "d7ee62471a325da5e6f51703aa8f9b2a74637fa3f5a6051f5cd929a00b40269c",
"trailing_zeros_01.out": "eb7ce8bd6a48648b1624787832be145375e25062641a432c4fc5390fb7d1d9c6",
"trailing_zeros_02.in": "e40e4dbc1bb13f5a6a0fad288d7da2f4007526d1cdb6632a2f6a40033f1af53b",
"trailing_zeros_02.out": "05b82dde50ff688d42a2c9cd38351cbbcbc485cfbec63d879ef23f6e6ab29bf2",
"trailing_zeros_03.in": "a7f7ada7cbc223a385c765523484834e632deb463d22ef048e41b0e6d9a3fc59",
"trailing_zeros_03.out": "c2e2238f0bdbf43745508392d154f5652b6804be112a9bf4ec258a2c7ef9f54a",
"trailing_zeros_04.in": "b0bbf3795866d50f4f228d1937e55f78ecbce9dfbf7e87c944e6ccc44a683274",
"trailing_zeros_04.out": "b0db8327ac86cd4c8a2c54db17d8784d0259ab1d7a333aea351e065b99276988",
"trailing_zeros_05.in": "d52903a178ca10e834ac3ff64dc6f8fd9a5fc290d3a360a007f205b01f58b49b",
"trailing_zeros_05.out": "d18952c8afca195ae731222fa2d17b2006af94c0e020e65e5e141a75aa85278d",
"trailing_zeros_06.in": "9f546cab6507999f763333496b7221678357359afff753f6c8af10b8abb92918",
"trailing_zeros_06.out": "2fcca3b0d792866967dbb4d39d7ab92a881bafdca72b79b7ced12d842194cc88",
"trailing_zeros_07.in": "01a485a7c69687cddbaf524ea0a81938df7d9973a69ef50f8b5b377f7c02b865",
"trailing_zeros_07.out": "981a66748b261d7ef2327d125003835b1ad68365a7f7630a4902ddd170e76d8d",
"trailing_zeros_08.in": "b5b1843249e37a0821798c0f9ccd266fe722d141da6fe6f68ead233c032b3b17",
"trailing_zeros_08.out": "f1650f98f696f2a23ab84126cae1333605ae568fa28791e1b8333e6e511ef9f3",
"trailing_zeros_09.in": "c302ac19be538dab27d632df15c45aac9d263dc040269331e793cad2fca0b754",
"trailing_zeros_09.out": "e465517963a8ca3a28c206253ea97c4e8e82ad0d63fa9802380f9dbb7652a8a2",
"zero_00.in": "28ead408ac716092d7cc8b862ffd4513880edf35bed2b941acbf31a3c4b9bf2d",
"zero_00.out": "a2db7544559db45401279e6a4fe895ade4648661fa550ea0aab611b17f71e1d0",
"zero_01.in": "094f939224863ba5ee1aabaad2acc7708ef31ac4aa5c2902b0d8b9e342100ce5",
"zero_01.out": "34e9a3077c280c96e1cd0c80c07a1e8026cfe645a3e5a92a5175e949b24e614e",
"zero_02.in": "81faf7bfadc29c0acff21760018ddf4aef43bc7d029aa05ba5350e1f53f55f41",
"zero_02.out": "90211b509d0774f95d5f02f1ee59995d969a0da1d195323ed68ba537a23c7244"
}
46 changes: 46 additions & 0 deletions math/consecutive_terms_of_linear_recurrent_sequence/info.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
title = 'Consecutive Terms of Linear Recurrent Sequence'
timelimit = 10.0
forum = 'https://github.com/yosupo06/library-checker-problems/issues/1007'

[[tests]]
name = "example.in"
number = 3

[[tests]]
name = "small.cpp"
number = 10

[[tests]]
name = "max_random.cpp"
number = 3

[[tests]]
name = "near_65536.cpp"
number = 3

[[tests]]
name = "random.cpp"
number = 3

[[tests]]
name = "trailing_zeros.cpp"
number = 10

[[tests]]
name = "zero.cpp"
number = 3

[[solutions]]
name = "naive.cpp"
allow_re = true

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

[params]
D_MAX = 100_000
M_MAX = 500_000
K_MAX = 1_000_000_000_000_000_000
MOD = 998_244_353
Loading

0 comments on commit d036b80

Please sign in to comment.