From b1926b5e30e0fa67d1a8875290460cebb269a509 Mon Sep 17 00:00:00 2001 From: kzrnm Date: Sun, 4 Feb 2024 00:39:03 +0900 Subject: [PATCH] power --- math/addition_of_hex_big_integers/base.hpp | 3 +- .../gen/power.cpp | 75 +++++++++++++++++++ math/addition_of_hex_big_integers/hash.json | 4 + math/addition_of_hex_big_integers/info.toml | 3 + math/division_of_hex_big_integers/base.hpp | 3 +- .../gen/power.cpp | 75 +++++++++++++++++++ math/division_of_hex_big_integers/hash.json | 2 + math/division_of_hex_big_integers/info.toml | 3 + .../base.hpp | 3 +- .../gen/power.cpp | 75 +++++++++++++++++++ .../hash.json | 4 + .../info.toml | 3 + 12 files changed, 250 insertions(+), 3 deletions(-) create mode 100644 math/addition_of_hex_big_integers/gen/power.cpp create mode 100644 math/division_of_hex_big_integers/gen/power.cpp create mode 100644 math/multiplication_of_hex_big_integers/gen/power.cpp diff --git a/math/addition_of_hex_big_integers/base.hpp b/math/addition_of_hex_big_integers/base.hpp index 6c0b703df..f838e39ee 100644 --- a/math/addition_of_hex_big_integers/base.hpp +++ b/math/addition_of_hex_big_integers/base.hpp @@ -795,9 +795,10 @@ struct BigInteger } if (i) rv.insert(begin(rv), x[i - 1]); + _shrink(rv); } - _shrink(qv), _shrink(rv); + _shrink(qv); _right_shift(rv.begin(), rv.end(), shift); _shrink(rv); diff --git a/math/addition_of_hex_big_integers/gen/power.cpp b/math/addition_of_hex_big_integers/gen/power.cpp new file mode 100644 index 000000000..73a44e7af --- /dev/null +++ b/math/addition_of_hex_big_integers/gen/power.cpp @@ -0,0 +1,75 @@ +#include +#include +#include +using namespace std; + +#include "random.h" +#include "../params.h" + +char make_hex(int x) +{ + assert(0 <= x && x < 16); + if (x < 10) + return char('0' + x); + else + return char('A' + x - 10); +} + +string make_num(Random &gen, int n, bool negative) +{ + string x; + for (int i = 0; i < n; ++i) + x += make_hex(gen.uniform(0, 15)); + if (n >= 2) + x[0] = make_hex(gen.uniform(1, 15)); + if (negative && x != "0") + x = "-" + x; + return x; +} + +int main(int, char *argv[]) +{ + long long seed = atoll(argv[1]); + vector A, B; + int sm = 0; + + A.emplace_back("1"); + B.emplace_back("1"); + + for (int t = 0; t < T_MAX - 1; ++t) + { + int length = t / 3 + 3; + string a(length, '0'); + a[0] = '1'; + + string b = seed ? "-" : ""; + + switch (t % 3) + { + case 0: + b += "10"; + break; + case 1: + b += a.substr(0, length / 2); + break; + default: + b += a; + break; + } + + if (sm + a.size() + b.size() > SUM_OF_CHARACTER_LENGTH) + { + goto FINISH; + } + sm += a.size() + b.size(); + A.emplace_back(a); + B.emplace_back(b); + } + +FINISH: + printf("%d\n", (int)A.size()); + for (int i = 0; i < (int)A.size(); i++) + { + printf("%s %s\n", A[i].c_str(), B[i].c_str()); + } +} diff --git a/math/addition_of_hex_big_integers/hash.json b/math/addition_of_hex_big_integers/hash.json index 0e62e679b..1e42f3b7f 100644 --- a/math/addition_of_hex_big_integers/hash.json +++ b/math/addition_of_hex_big_integers/hash.json @@ -31,6 +31,10 @@ "medium_01.out": "aa9754cca30e91a69a78bd6feadefb89b07669b0bffb1584e40f440ee13f0470", "medium_02.in": "e2527dd397b0560b41c84bfd699fb99c63b3413e6c001877528365961a1cb722", "medium_02.out": "c1cf6b6c642f3b51b998af2393526fd8de9f47d07b2a27bfebda23625c0bcea9", + "power_00.in": "7bd820adc7f5d72adb5f87a7077b7f2bdfd79dd396fe4e22d856f51585c8f8ef", + "power_00.out": "9b2c5945bcec7f708728be1664ce123a159a4823ff4c7fd011fd6f41522e38f8", + "power_01.in": "6af69c50a575ecbfc5356915a15dba54ddda98064c76f4d983a7ee95b3926042", + "power_01.out": "e0fba8f78f78adf464a351ecb053e9d9f7b7cb547d25d9249a8b7957b0096ac8", "small_00.in": "935f5d39619bb70a3cf65f5fe1f8d79ee8827a3906691f5b26305d2dc0571e74", "small_00.out": "ed5351a77d2c615f504db37279154124fc9510b64e0edca9b5c1669c4a92cea0", "sum_zero_00.in": "15347638e35e308e76c559d4f81ecd827667733b773be94b3cdccf627d0171d7", diff --git a/math/addition_of_hex_big_integers/info.toml b/math/addition_of_hex_big_integers/info.toml index 01293ec74..e07802687 100644 --- a/math/addition_of_hex_big_integers/info.toml +++ b/math/addition_of_hex_big_integers/info.toml @@ -23,6 +23,9 @@ forum = "https://github.com/yosupo06/library-checker-problems/issues/1101" [[tests]] name = "large_small.cpp" number = 1 +[[tests]] + name = "power.cpp" + number = 2 [[solutions]] name = "correct.py" diff --git a/math/division_of_hex_big_integers/base.hpp b/math/division_of_hex_big_integers/base.hpp index 6c0b703df..f838e39ee 100644 --- a/math/division_of_hex_big_integers/base.hpp +++ b/math/division_of_hex_big_integers/base.hpp @@ -795,9 +795,10 @@ struct BigInteger } if (i) rv.insert(begin(rv), x[i - 1]); + _shrink(rv); } - _shrink(qv), _shrink(rv); + _shrink(qv); _right_shift(rv.begin(), rv.end(), shift); _shrink(rv); diff --git a/math/division_of_hex_big_integers/gen/power.cpp b/math/division_of_hex_big_integers/gen/power.cpp new file mode 100644 index 000000000..73a44e7af --- /dev/null +++ b/math/division_of_hex_big_integers/gen/power.cpp @@ -0,0 +1,75 @@ +#include +#include +#include +using namespace std; + +#include "random.h" +#include "../params.h" + +char make_hex(int x) +{ + assert(0 <= x && x < 16); + if (x < 10) + return char('0' + x); + else + return char('A' + x - 10); +} + +string make_num(Random &gen, int n, bool negative) +{ + string x; + for (int i = 0; i < n; ++i) + x += make_hex(gen.uniform(0, 15)); + if (n >= 2) + x[0] = make_hex(gen.uniform(1, 15)); + if (negative && x != "0") + x = "-" + x; + return x; +} + +int main(int, char *argv[]) +{ + long long seed = atoll(argv[1]); + vector A, B; + int sm = 0; + + A.emplace_back("1"); + B.emplace_back("1"); + + for (int t = 0; t < T_MAX - 1; ++t) + { + int length = t / 3 + 3; + string a(length, '0'); + a[0] = '1'; + + string b = seed ? "-" : ""; + + switch (t % 3) + { + case 0: + b += "10"; + break; + case 1: + b += a.substr(0, length / 2); + break; + default: + b += a; + break; + } + + if (sm + a.size() + b.size() > SUM_OF_CHARACTER_LENGTH) + { + goto FINISH; + } + sm += a.size() + b.size(); + A.emplace_back(a); + B.emplace_back(b); + } + +FINISH: + printf("%d\n", (int)A.size()); + for (int i = 0; i < (int)A.size(); i++) + { + printf("%s %s\n", A[i].c_str(), B[i].c_str()); + } +} diff --git a/math/division_of_hex_big_integers/hash.json b/math/division_of_hex_big_integers/hash.json index 520ebc218..a377acc56 100644 --- a/math/division_of_hex_big_integers/hash.json +++ b/math/division_of_hex_big_integers/hash.json @@ -35,6 +35,8 @@ "medium_01.out": "b951572e5248e07af662a6b4a159d059f9c79cef457f329328ca60e9b4b0a5af", "medium_02.in": "b6b2225cdc6eac35c4ef0fd692168bbe5b5be5c424443cef4423985547e3052b", "medium_02.out": "cfa27cae4ecf642022bff425f11c4c8d577462578290b671c08e3c9a57194e52", + "power_00.in": "7bd820adc7f5d72adb5f87a7077b7f2bdfd79dd396fe4e22d856f51585c8f8ef", + "power_00.out": "441a031a978d422efad58dbfa4f68da322e0095d88bd3fa07a4beaf5d8a87fe2", "r_nearly_zero_00.in": "72af7ac638806933d5ea7f8e2bc0c8d1cc8af795cf2ad695dbbb40774707b24b", "r_nearly_zero_00.out": "8ab23fcc92aeea97f569bb2b70f804db9c7d12d03445d4c2a37de0c1a502e153", "r_nearly_zero_01.in": "dfcd8d758dbfa96fc85f2ea2cdfecb888ca9f9b604bb1cb598d280c3fa6b84a7", diff --git a/math/division_of_hex_big_integers/info.toml b/math/division_of_hex_big_integers/info.toml index 891aea3e7..7075b45a1 100644 --- a/math/division_of_hex_big_integers/info.toml +++ b/math/division_of_hex_big_integers/info.toml @@ -20,6 +20,9 @@ forum = "https://github.com/yosupo06/library-checker-problems/issues/1101" [[tests]] name = "a_max_b_random.cpp" number = 3 +[[tests]] + name = "power.cpp" + number = 1 [[tests]] name = "r_nearly_zero.cpp" number = 3 diff --git a/math/multiplication_of_hex_big_integers/base.hpp b/math/multiplication_of_hex_big_integers/base.hpp index 6c0b703df..f838e39ee 100644 --- a/math/multiplication_of_hex_big_integers/base.hpp +++ b/math/multiplication_of_hex_big_integers/base.hpp @@ -795,9 +795,10 @@ struct BigInteger } if (i) rv.insert(begin(rv), x[i - 1]); + _shrink(rv); } - _shrink(qv), _shrink(rv); + _shrink(qv); _right_shift(rv.begin(), rv.end(), shift); _shrink(rv); diff --git a/math/multiplication_of_hex_big_integers/gen/power.cpp b/math/multiplication_of_hex_big_integers/gen/power.cpp new file mode 100644 index 000000000..73a44e7af --- /dev/null +++ b/math/multiplication_of_hex_big_integers/gen/power.cpp @@ -0,0 +1,75 @@ +#include +#include +#include +using namespace std; + +#include "random.h" +#include "../params.h" + +char make_hex(int x) +{ + assert(0 <= x && x < 16); + if (x < 10) + return char('0' + x); + else + return char('A' + x - 10); +} + +string make_num(Random &gen, int n, bool negative) +{ + string x; + for (int i = 0; i < n; ++i) + x += make_hex(gen.uniform(0, 15)); + if (n >= 2) + x[0] = make_hex(gen.uniform(1, 15)); + if (negative && x != "0") + x = "-" + x; + return x; +} + +int main(int, char *argv[]) +{ + long long seed = atoll(argv[1]); + vector A, B; + int sm = 0; + + A.emplace_back("1"); + B.emplace_back("1"); + + for (int t = 0; t < T_MAX - 1; ++t) + { + int length = t / 3 + 3; + string a(length, '0'); + a[0] = '1'; + + string b = seed ? "-" : ""; + + switch (t % 3) + { + case 0: + b += "10"; + break; + case 1: + b += a.substr(0, length / 2); + break; + default: + b += a; + break; + } + + if (sm + a.size() + b.size() > SUM_OF_CHARACTER_LENGTH) + { + goto FINISH; + } + sm += a.size() + b.size(); + A.emplace_back(a); + B.emplace_back(b); + } + +FINISH: + printf("%d\n", (int)A.size()); + for (int i = 0; i < (int)A.size(); i++) + { + printf("%s %s\n", A[i].c_str(), B[i].c_str()); + } +} diff --git a/math/multiplication_of_hex_big_integers/hash.json b/math/multiplication_of_hex_big_integers/hash.json index ed6d8a9a1..74eeec1d1 100644 --- a/math/multiplication_of_hex_big_integers/hash.json +++ b/math/multiplication_of_hex_big_integers/hash.json @@ -35,6 +35,10 @@ "medium_01.out": "da3e986b1c52239513f18cbd8c14540ff8dbf11ea78c28fb1e16da7fdcd3f54c", "medium_02.in": "e2527dd397b0560b41c84bfd699fb99c63b3413e6c001877528365961a1cb722", "medium_02.out": "a7bc7f3a54b0c0d75e954aa6e191bd47cf1a44d00709a6ae460e2a601dbfede8", + "power_00.in": "7bd820adc7f5d72adb5f87a7077b7f2bdfd79dd396fe4e22d856f51585c8f8ef", + "power_00.out": "78ab95f5fe146343244b08e74467b0455ae3b8fd81de8008a330e5f2ded507d2", + "power_01.in": "6af69c50a575ecbfc5356915a15dba54ddda98064c76f4d983a7ee95b3926042", + "power_01.out": "ea4aee46a9b1ae78e3196e7ab650f6a84b281834d6140f67998a8ad090725c91", "small_00.in": "935f5d39619bb70a3cf65f5fe1f8d79ee8827a3906691f5b26305d2dc0571e74", "small_00.out": "1300e69b8042edaf33cb38e423c9ad082a5fc99aa46a0d492f8bcc9fa0febe21", "zero_00.in": "8ac32fcbe448675e6909d8bcdb7664f8eea13c5b1cf6b72d93ab9a275fa7405b", diff --git a/math/multiplication_of_hex_big_integers/info.toml b/math/multiplication_of_hex_big_integers/info.toml index 589e75a83..11679abd2 100644 --- a/math/multiplication_of_hex_big_integers/info.toml +++ b/math/multiplication_of_hex_big_integers/info.toml @@ -20,6 +20,9 @@ forum = "https://github.com/yosupo06/library-checker-problems/issues/1101" [[tests]] name = "zero.cpp" number = 1 +[[tests]] + name = "power.cpp" + number = 2 [[tests]] name = "fft_killer.cpp" number = 2