{"id":375918,"date":"2024-05-21T06:37:18","date_gmt":"2024-05-21T06:37:18","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=375918"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=375918","title":{"rendered":"<span>\u0422\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0430 \u0434\u0435\u043b\u0435\u043d\u0438\u044f \u0431\u043e\u043b\u044c\u0448\u0438\u0445 \u0447\u0438\u0441\u0435\u043b \u043d\u0430 \u0421++ \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c Python C API<\/span>"},"content":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<h3>\u0412\u0432\u0435\u0434\u0435\u043d\u0438\u0435<\/h3>\n<p>\u0420\u0430\u043d\u0435\u0435 \u0431\u044b\u043b \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0439 <a href=\"https:\/\/habr.com\/ru\/articles\/811323\/\" rel=\"noopener noreferrer nofollow\">\u0410\u043b\u0433\u043e\u0440\u0438\u0442\u043c<\/a> \u0434\u0435\u043b\u0435\u043d\u0438\u044f 2W-\u0431\u0438\u0442\u043e\u0432\u044b\u0445 \u0447\u0438\u0441\u0435\u043b \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0439 \u043d\u0430\u0434 W-\u0431\u0438\u0442\u043e\u0432\u044b\u043c\u0438 \u0447\u0438\u0441\u043b\u0430\u043c\u0438. \u0414\u043b\u044f \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b\u0438\u0441\u044c \u0446\u0435\u043b\u044b\u0435 \u0447\u0438\u0441\u043b\u0430 \u044f\u0437\u044b\u043a\u0430 \u0421++, \u0447\u0442\u043e \u043d\u0435 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u043b\u043e \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0442\u044c, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, 128-\u0431\u0438\u0442\u043d\u044b\u0435 \u0446\u0435\u043b\u044b\u0435 \u0447\u0438\u0441\u043b\u0430. \u041e\u0434\u043d\u0430\u043a\u043e, \u0432 \u044f\u0437\u044b\u043a Python \u0432\u0441\u0442\u0440\u043e\u0435\u043d\u0430 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0430 \u0446\u0435\u043b\u044b\u0445 \u0447\u0438\u0441\u0435\u043b \u043d\u0435\u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u043d\u043e\u0439 \u0448\u0438\u0440\u0438\u043d\u044b (Big Integer), \u0430 \u0442\u0430\u043a\u0436\u0435 \u0438\u043c\u0435\u0435\u0442\u0441\u044f API \u0434\u043b\u044f \u0432\u044b\u0437\u043e\u0432\u0430 \u043c\u0435\u0442\u043e\u0434\u043e\u0432 Python \u0438\u0437 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c \u043d\u0430 \u044f\u0437\u044b\u043a\u0435 \u0421\/\u0421++. \u042d\u0442\u043e \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043f\u0440\u043e\u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0440\u0430\u0437\u043d\u044b\u0435 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u044b \u0441 \u0447\u0438\u0441\u043b\u0430\u043c\u0438, \u0432 \u0442\u043e\u043c \u0447\u0438\u0441\u043b\u0435 \u0434\u0435\u043b\u0435\u043d\u0438\u0435, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0430 \u0441\u0442\u0440\u043e\u043a\u043e\u0432\u043e\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0447\u0438\u0441\u0435\u043b.<\/p>\n<p>\u0412 \u0434\u0430\u043d\u043d\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u0440\u0430\u0441\u043f\u0438\u0441\u0430\u043d\u044b \u0448\u0430\u0433\u0438 \u0434\u043b\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f Python C API \u0432 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0435 \u043d\u0430 \u044f\u0437\u044b\u043a\u0435 \u0421++, \u0430 \u0442\u0430\u043a\u0436\u0435 \u043f\u043e\u043a\u0430\u0437\u0430\u043d \u043f\u0440\u0438\u043c\u0435\u0440 \u0432\u044b\u0437\u043e\u0432\u0430 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u0430 \u0434\u0435\u043b\u0435\u043d\u0438\u044f \u0434\u0432\u0443\u0445 \u0446\u0435\u043b\u044b\u0445 \u0447\u0438\u0441\u0435\u043b \u0441 \u0432\u043e\u0437\u0432\u0440\u0430\u0442\u043e\u043c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0430 \u0432 \u0432\u0438\u0434\u0435 \u0441\u0442\u0440\u043e\u043a\u0438 \u0421. \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b\u0430\u0441\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0430\u044f \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u043d\u0430\u044f \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u044f:<\/p>\n<ul>\n<li>\n<p>Windows 11, WSL Ubuntu 22.04.3 LTS, GCC 12.3.0.<\/p>\n<\/li>\n<li>\n<p>IDE Visual Studio Code \u0430\u043a\u0442\u0443\u0430\u043b\u044c\u043d\u043e\u0439 \u0432\u0435\u0440\u0441\u0438\u0438.<\/p>\n<\/li>\n<li>\n<p>\u0412\u0441\u0442\u0440\u043e\u0435\u043d\u043d\u044b\u0439 \u0432 Ubuntu Python 3.10.<\/p>\n<\/li>\n<\/ul>\n<h3>\u041d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0430 \u0441\u0440\u0435\u0434\u044b<\/h3>\n<p>\u041f\u0440\u0435\u0434\u0432\u0430\u0440\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c \u043d\u0430\u0431\u043e\u0440 <em>build-essential<\/em> \u0438 \u0441\u0440\u0435\u0434\u0441\u0442\u0432\u043e \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0430 <em>python3-dev<\/em>.<\/p>\n<ol>\n<li>\n<p>\u041e\u0442\u043a\u0440\u044b\u0432\u0430\u0435\u043c \u043a\u043e\u043d\u0441\u043e\u043b\u044c <em>Ubuntu<\/em> \u0438 \u0441\u043e\u0437\u0434\u0430\u0435\u043c \u0434\u0438\u0440\u0435\u043a\u0442\u043e\u0440\u0438\u044e \u0441 \u043f\u0440\u043e\u0435\u043a\u0442\u043e\u043c:<\/p>\n<\/li>\n<\/ol>\n<pre><code class=\"bash\">mkdir division_test<\/code><\/pre>\n<ol start=\"2\">\n<li>\n<p>\u041f\u0435\u0440\u0435\u0445\u043e\u0434\u0438\u043c \u0432 \u0441\u043e\u0437\u0434\u0430\u043d\u043d\u044b\u0439 \u043a\u0430\u0442\u0430\u043b\u043e\u0433 \u0438 \u0441\u043e\u0437\u0434\u0430\u0435\u043c \u0442\u043e\u0447\u043a\u0443 \u0432\u0445\u043e\u0434\u0430 \u0432 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0443:<\/p>\n<\/li>\n<\/ol>\n<pre><code class=\"bash\">cd division_test touch main.cpp<\/code><\/pre>\n<ol start=\"3\">\n<li>\n<p>\u0417\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u043c IDE Visual Studio Code. \u0423\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u043c \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u044f WSL \u0438 C\/C++.<\/p>\n<\/li>\n<li>\n<p>\u041f\u0435\u0440\u0435\u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u043c Visual Studio Code, \u0438 \u0447\u0435\u0440\u0435\u0437 IDE \u043e\u0442\u043a\u0440\u044b\u0432\u0430\u0435\u043c <strong>\u0434\u0438\u0440\u0435\u043a\u0442\u043e\u0440\u0438\u044e<\/strong> \u0441\u043e\u0437\u0434\u0430\u043d\u043d\u043e\u0433\u043e \u043f\u0440\u043e\u0435\u043a\u0442\u0430, <em>division_test<\/em>. \u0412 \u0438\u0442\u043e\u0433\u0435, \u043d\u0430 \u043f\u0430\u043d\u0435\u043b\u0438 EXPLORER \u0434\u043e\u043b\u0436\u0435\u043d \u043e\u0442\u043e\u0431\u0440\u0430\u0437\u0438\u0442\u044c\u0441\u044f \u0444\u0430\u0439\u043b <em>main.cpp<\/em>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043d\u0430\u0434\u043e \u043e\u0442\u043a\u0440\u044b\u0442\u044c \u0434\u043b\u044f \u0440\u0435\u0434\u0430\u043a\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f.<\/p>\n<\/li>\n<li>\n<p>\u041a\u043e\u043f\u0438\u0440\u0443\u0435\u043c\/\u0441\u043e\u0437\u0434\u0430\u0435\u043c \u0442\u0435\u0441\u0442\u043e\u0432\u044b\u0439 \u0438\u0441\u0445\u043e\u0434\u043d\u044b\u0439 \u043a\u043e\u0434.<\/p>\n<\/li>\n<li>\n<p>\u0427\u0435\u0440\u0435\u0437 \u043c\u0435\u043d\u044e IDE \u00abTerminal\/Configure Default Build Task&#8230;\u00bb \u0441\u043e\u0437\u0434\u0430\u0435\u043c \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u044e \u0441\u0431\u043e\u0440\u043a\u0438 <em>tasks.json<\/em>.<\/p>\n<\/li>\n<li>\n<p>\u0412 \u0444\u0430\u0439\u043b \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0438 <em>tasks.json<\/em> \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u043b\u0438\u043d\u043a\u043e\u0432\u043a\u0443 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 Python, \u0430 \u0442\u0430\u043a\u0436\u0435 \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u043e\u043f\u0446\u0438\u0438: \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442 \u0421++20 \u0438 \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u044e \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0446\u0438\u0438 O3:<\/p>\n<\/li>\n<\/ol>\n<pre><code class=\"json\">... \"args\": [     \"-fdiagnostics-color=always\",     \"-O3\",     \"-std=c++20\",     \"${file}\",     \"-o\",     \"${fileDirname}\/${fileBasenameNoExtension}\",     \"-lpython3.10\" ], ...<\/code><\/pre>\n<ol start=\"8\">\n<li>\n<p>\u0410\u043a\u0442\u0438\u0432\u0438\u0440\u0443\u0435\u043c \u0442\u043e\u0447\u043a\u0443 \u0432\u0445\u043e\u0434\u0430: \u0444\u0430\u0439\u043b <em>main.cpp<\/em>. \u041f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043e\u0447\u043d\u043e\u0433\u043e \u0444\u0430\u0439\u043b\u0430 Python<\/p>\n<\/li>\n<\/ol>\n<pre><code class=\"cpp\">#include &lt;python3.10\/Python.h><\/code><\/pre>\n<ol start=\"9\">\n<li>\n<p>\u041e\u0442\u043a\u0440\u044b\u0432\u0430\u0435\u043c \u0442\u0435\u0440\u043c\u0438\u043d\u0430\u043b \u00abTerminal\/New Terminal\u00bb, \u0430\u043a\u0442\u0438\u0432\u0438\u0440\u0443\u0435\u043c \u0444\u043e\u043a\u0443\u0441 (\u043a\u0443\u0440\u0441\u043e\u0440) \u043d\u0430\u00a0\u0442\u0435\u0440\u043c\u0438\u043d\u0430\u043b\u0435 \u0438 \u043d\u0430\u0436\u0438\u043c\u0430\u0435\u043c \u00abCtrl+Shift+B\u00bb, \u043d\u0435\u00a0\u0437\u0430\u0431\u044b\u0432 \u043f\u0435\u0440\u0435\u043a\u043b\u044e\u0447\u0438\u0442\u044c\u0441\u044f \u043d\u0430\u00a0\u0430\u043d\u0433\u043b\u0438\u0439\u0441\u043a\u0438\u0439 \u044f\u0437\u044b\u043a EN. \u041f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0430 \u0434\u043e\u043b\u0436\u043d\u0430 \u0441\u043e\u0431\u0440\u0430\u0442\u044c\u0441\u044f. \u0417\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u044c \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0443 \u043c\u043e\u0436\u043d\u043e \u0432 \u0442\u0435\u0440\u043c\u0438\u043d\u0430\u043b\u0435 \u043a\u0430\u043a \u043e\u0431\u044b\u0447\u043d\u043e: <strong>.\/main<\/strong>.<\/p>\n<\/li>\n<\/ol>\n<h3>\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 API C Python<\/h3>\n<p>\u041f\u043e\u0441\u043b\u0435 \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438 \u0441\u0440\u0435\u0434\u044b \u0438 \u0441\u0431\u043e\u0440\u043a\u0438 \u0442\u0435\u0441\u0442\u043e\u0432\u043e\u0433\u043e \u043f\u0440\u043e\u0435\u043a\u0442\u0430 \u043c\u043e\u0436\u043d\u043e \u0441\u0432\u043e\u0431\u043e\u0434\u043d\u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u043c\u0435\u0442\u043e\u0434\u0430\u043c\u0438 API C Python.<\/p>\n<p>\u0414\u043b\u044f \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0434\u0435\u043b\u0435\u043d\u0438\u044f \u0434\u0432\u0443\u0445 128-\u0431\u0438\u0442\u043d\u044b\u0445 \u0447\u0438\u0441\u0435\u043b \u0431\u044b\u043b \u0441\u043e\u0437\u0434\u0430\u043d \u0432\u0441\u043f\u043e\u043c\u043e\u0433\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u043a\u043b\u0430\u0441\u0441 <em>PythonCaller<\/em>.<\/p>\n<details class=\"spoiler\">\n<summary>\u0412\u0441\u043f\u043e\u043c\u043e\u0433\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u043a\u043b\u0430\u0441\u0441 \u0434\u0435\u043b\u0435\u043d\u0438\u044f \u0447\u0438\u0441\u0435\u043b \u043d\u0430 API C Python<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"cpp\">class PythonCaller { public:      PythonCaller() {         Py_Initialize();         mMain = PyImport_AddModule(\"__main__\");         mGlobalDictionary = PyModule_GetDict(mMain);         mLocalDictionary = PyDict_New();         std::cout &lt;&lt; \"Python was initialized!\\n\";     }      ~PythonCaller() {         Py_Finalize();         std::cout &lt;&lt; \"~Python was finalized!\\n\";     }      \/**      * \u0414\u0435\u043b\u0438\u0442 \u0434\u0432\u0430 128-\u0431\u0438\u0442\u043d\u044b\u0445 \u0447\u0438\u0441\u043b\u0430.      * @param X \u0414\u0435\u043b\u0438\u043c\u043e\u0435.      * @param Y \u0414\u0435\u043b\u0438\u0442\u0435\u043b\u044c.      * @return \u0427\u0430\u0441\u0442\u043d\u043e\u0435 \u043e\u0442 \u0434\u0435\u043b\u0435\u043d\u0438\u044f, \u043e\u0431\u044a\u0435\u043a\u0442 Python.     *\/     PyObject* Divide(U128 X, U128 Y) const {         const char* pythonScript = \"quotient = nominator \/\/ denominator\\n\";         PyDict_SetItemString(mLocalDictionary, \"nominator\", PyLong_FromString(X.value().c_str(), nullptr, 10));         PyDict_SetItemString(mLocalDictionary, \"denominator\", PyLong_FromString(Y.value().c_str(), nullptr, 10));         PyRun_String(pythonScript, Py_file_input, mGlobalDictionary, mLocalDictionary);         return PyDict_GetItemString(mLocalDictionary, \"quotient\");     }     \/**      * \u0421\u0440\u0430\u0432\u043d\u0438\u0432\u0430\u0435\u0442 \u0434\u0432\u0430 \u0447\u0430\u0441\u0442\u043d\u044b\u0445 \u043e\u0442 \u0434\u0435\u043b\u0435\u043d\u0438\u044f.      * @param quotient \u0427\u0430\u0441\u0442\u043d\u043e\u0435 \u043e\u0442 \u0434\u0435\u043b\u0435\u043d\u0438\u044f Python, \u043e\u0431\u044a\u0435\u043a\u0442 Python.      * @param reference \u0427\u0430\u0441\u0442\u043d\u043e\u0435 \u043e\u0442 \u0434\u0435\u043b\u0435\u043d\u0438\u044f \u0421++, \u0441\u0442\u0440\u043e\u043a\u0430.     *\/     bool Compare(PyObject* quotient, const char* reference) const {         PyObject* repr = PyObject_Repr(quotient);         PyObject* str = PyUnicode_AsEncodedString(repr, \"utf-8\", \"~E~\");         const char *bytes = PyBytes_AsString(str);         const bool is_ok = strcmp(bytes, reference) == 0;         if (!is_ok) {             printf(\"Python: %s\\n\", bytes);             printf(\"C++: %s\\n\", reference);         }         Py_XDECREF(repr);         Py_XDECREF(str);         return is_ok;     } private:      PyObject* mMain = nullptr;     PyObject* mGlobalDictionary = nullptr;     PyObject* mLocalDictionary = nullptr; };<\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<p>\u0412 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u0435 \u043a\u043b\u0430\u0441\u0441\u0430 \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u0441\u0440\u0435\u0434\u0430 Python \u0441 \u0432\u0441\u043f\u043e\u043c\u043e\u0433\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u043c\u0438 \u0441\u043b\u043e\u0432\u0430\u0440\u044f\u043c\u0438 \u0434\u043b\u044f \u0432\u0432\u043e\u0434\u0430-\u0432\u044b\u0432\u043e\u0434\u0430 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u043e\u0432 \u0441\u0447\u0435\u0442\u0430.<\/p>\n<p>\u0414\u043b\u044f \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0438 \u0434\u043b\u0438\u043d\u043d\u043e\u0433\u043e Python \u0447\u0438\u0441\u043b\u0430 \u0442\u0438\u043f\u0430 <em>int<\/em> \u0438\u0437 \u0421++ \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f API \u043c\u0435\u0442\u043e\u0434 <em>PyLong_FromString<\/em>, \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u044e\u0449\u0438\u0439 \u0441\u0442\u0440\u043e\u043a\u043e\u0432\u043e\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0447\u0438\u0441\u043b\u0430 (const char*, \u043f\u0435\u0440\u0432\u044b\u0439 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442) \u0438 \u043e\u0441\u043d\u043e\u0432\u0430\u043d\u0438\u0435 \u0441\u0438\u0441\u0442\u0435\u043c\u044b \u0441\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f (\u0442\u0440\u0435\u0442\u0438\u0439 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442). \u0421\u043a\u0440\u0438\u043f\u0442 Python \u0441\u043e\u0437\u0434\u0430\u0435\u0442\u0441\u044f \u0432 \u0432\u0438\u0434\u0435 \u0441\u0442\u0440\u043e\u043a\u0438 \u0441 \u043d\u0435\u043f\u043e\u0441\u0440\u0435\u0434\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0439 \u0437\u0430\u043f\u0438\u0441\u044c\u044e \u0434\u0435\u043b\u0435\u043d\u0438\u044f \u0447\u0435\u0440\u0435\u0437 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435, \u0438\u043c\u0435\u043d\u0430 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0441\u043e\u0432\u043f\u0430\u0434\u0430\u044e\u0442 \u0441 \u043a\u043b\u044e\u0447\u0430\u043c\u0438 \u043e\u0431\u043c\u0435\u043d\u043d\u043e\u0433\u043e \u0441\u043b\u043e\u0432\u0430\u0440\u044f <em>mLocalDictionary<\/em>. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0434\u0435\u043b\u0435\u043d\u0438\u044f (\u0447\u0430\u0441\u0442\u043d\u043e\u0435) \u0431\u0443\u0434\u0435\u0442 \u0434\u043e\u0441\u0442\u0443\u043f\u0435\u043d \u043f\u043e \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0435\u043c\u0443 \u043a\u043b\u044e\u0447\u0443 \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u0447\u0435\u0440\u0435\u0437 API \u043c\u0435\u0442\u043e\u0434 <em>PyDict_GetItemString<\/em> \u0432 \u0432\u0438\u0434\u0435 Python \u043e\u0431\u044a\u0435\u043a\u0442\u0430.<\/p>\n<p>\u0414\u043b\u044f \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u044f Python \u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u0432 \u0441\u0442\u0440\u043e\u043a\u0443 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442\u0441\u044f \u0442\u0440\u0438 API \u043c\u0435\u0442\u043e\u0434\u0430:<\/p>\n<ul>\n<li>\n<p><strong>PyObject_Repr<\/strong>,<\/p>\n<\/li>\n<li>\n<p><strong>PyUnicode_AsEncodedString<\/strong>,<\/p>\n<\/li>\n<li>\n<p><strong>PyBytes_AsString<\/strong>.<\/p>\n<\/li>\n<\/ul>\n<p>\u041f\u0435\u0440\u0432\u044b\u0439 \u043c\u0435\u0442\u043e\u0434 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u0443\u0435\u0442 \u043e\u0431\u044a\u0435\u043a\u0442 Python \u0432\u043e \u0432\u043d\u0443\u0442\u0440\u0435\u043d\u043d\u0435\u0435 \u0441\u0442\u0440\u043e\u043a\u043e\u0432\u043e\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435 Python, \u0432\u044b\u0434\u0430\u0432\u0430\u044f \u043d\u0430 \u0432\u044b\u0445\u043e\u0434 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u043d\u044b\u0439 \u043e\u0431\u044a\u0435\u043a\u0442 Python. \u042d\u0442\u043e \u0430\u043d\u0430\u043b\u043e\u0433 \u043c\u0435\u0442\u043e\u0434\u0430 <em>repr(.)<\/em> Python.<\/p>\n<p>\u0412\u0442\u043e\u0440\u043e\u0439 \u043c\u0435\u0442\u043e\u0434 \u0444\u043e\u0440\u043c\u0438\u0440\u0443\u0435\u0442 \u0431\u0430\u0439\u0442\u043e\u0432\u043e\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0441\u0442\u0440\u043e\u043a\u0438, \u043f\u0440\u0438\u0433\u043e\u0434\u043d\u043e\u0435 \u0434\u043b\u044f \u043f\u0435\u0440\u0435\u0434\u0430\u0447\u0438 \u0432 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043a\u0430\u043d\u0430\u043b \u0441\u0432\u044f\u0437\u0438. \u041d\u0430 \u0432\u044b\u0445\u043e\u0434\u0435 \u0438\u043c\u0435\u0435\u043c \u043e\u0431\u044a\u0435\u043a\u0442 Python.<\/p>\n<p>\u041d\u0430\u043a\u043e\u043d\u0435\u0446, \u0442\u0440\u0435\u0442\u0438\u0439 \u043c\u0435\u0442\u043e\u0434 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043f\u043e \u0433\u043e\u0442\u043e\u0432\u043e\u043c\u0443 \u043e\u0431\u044a\u0435\u043a\u0442\u0443 Python \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c \u043d\u0430 \u0431\u0430\u0439\u0442\u044b \u0438\u0441\u043a\u043e\u043c\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0438. \u0412 \u043d\u0430\u0448\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0430\u043d\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u044e\u0442\u0441\u044f \u0447\u0438\u0441\u043b\u0430, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0431\u0430\u0439\u0442\u044b \u0441\u043e\u0432\u043f\u0430\u0434\u0430\u044e\u0442 \u0441 \u0441\u0438\u043c\u0432\u043e\u043b\u0430\u043c\u0438: \u0446\u0438\u0444\u0440\u0430\u043c\u0438 0&#8230;9, \u0437\u043d\u0430\u043a\u043e\u043c \u043c\u0438\u043d\u0443\u0441, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u044d\u0442\u0438 \u0431\u0430\u0439\u0442\u044b \u043c\u043e\u0436\u043d\u043e \u043d\u0430\u043f\u0440\u044f\u043c\u0443\u044e \u0441\u0440\u0430\u0432\u043d\u0438\u0432\u0430\u0442\u044c \u0441 \u0431\u0430\u0439\u0442\u0430\u043c\u0438 \u0441\u0442\u0440\u043e\u043a\u043e\u0432\u043e\u0433\u043e \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0434\u0440\u0443\u0433\u0438\u0445 \u0447\u0438\u0441\u0435\u043b &#8212; \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u043e\u0432 \u0441\u0447\u0435\u0442\u0430 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0430 \u043d\u0430 \u0421++.<\/p>\n<p>\u041d\u0430\u0431\u043e\u0440 \u043c\u0435\u0442\u043e\u0434\u043e\u0432 \u0434\u043b\u044f \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d \u043d\u0438\u0436\u0435.<\/p>\n<details class=\"spoiler\">\n<summary>\u041c\u0435\u0442\u043e\u0434\u044b \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0430 \u0434\u0435\u043b\u0435\u043d\u0438\u044f 128-\u0431\u0438\u0442\u043d\u044b\u0445 \u0447\u0438\u0441\u0435\u043b<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"cpp\">#include &lt;algorithm> #include &lt;cassert> #include &lt;cmath> #include &lt;cstdint> #include &lt;iostream> #include &lt;random> #include &lt;string> #include &lt;string.h> #include &lt;python3.10\/Python.h>  using u64 = uint64_t; using ULOW = u64; \/\/ \u0422\u0438\u043f \u043f\u043e\u043b\u043e\u0432\u0438\u043d\u043e\u043a: \u0441\u0442\u0430\u0440\u0448\u0435\u0439 \u0438 \u043c\u043b\u0430\u0434\u0448\u0435\u0439 \u0447\u0430\u0441\u0442\u0435\u0439 \u0441\u043e\u0441\u0442\u0430\u0432\u043d\u043e\u0433\u043e \u0447\u0438\u0441\u043b\u0430.  static_assert(CHAR_BIT == 8);  struct Quadrupole { \/\/ \u0421\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430 \u0434\u043b\u044f \u0437\u0430\u0434\u0430\u043d\u0438\u044f \u0434\u0440\u043e\u0431\u0438 (A*M + B) \/ (C*M + D).                     \/\/ M - \u043c\u043d\u043e\u0436\u0438\u0442\u0435\u043b\u044c \u0441\u0438\u0441\u0442\u0435\u043c\u044b \u0441\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f, 2^W, W - \u0431\u0438\u0442\u043e\u0432\u0430\u044f \u0448\u0438\u0440\u0438\u043d\u0430 \u043f\u043e\u043b\u043e\u0432\u0438\u043d\u043e\u043a.     ULOW A;     ULOW B;     ULOW C;     ULOW D; };  struct Signess { \/\/ \u0421\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430 \u0434\u043b\u044f \u0437\u0430\u0434\u0430\u043d\u0438\u044f \u0437\u043d\u0430\u043a\u043e\u0432 \u0434\u0432\u0443\u0445 \u0447\u0438\u0441\u0435\u043b.     bool s1;     bool s2; };  static auto const seed = std::random_device{}();  \/***  * \u0413\u0435\u043d\u0435\u0440\u0430\u0442\u043e\u0440 \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u044b\u0445 \u0447\u0438\u0441\u0435\u043b.  *\/ auto roll_ulow = [urbg = std::mt19937{seed},                 distr = std::uniform_int_distribution&lt;ULOW>{}]() mutable -> ULOW {     return distr(urbg); };  auto roll_uint = [urbg = std::mt19937{seed},                 distr = std::uniform_int_distribution&lt;uint>{}]() mutable -> uint {     return distr(urbg); };  auto roll_bool = [urbg = std::mt19937{seed},                 distr = std::uniform_int_distribution&lt;uint>{}]() mutable -> bool {     return distr(urbg) % 2; };  \/**  * \u0422\u0435\u0441\u0442 \u0434\u0435\u043b\u0435\u043d\u0438\u044f \u0434\u0432\u0443\u0445 128-\u0431\u0438\u0442\u043d\u044b\u0445 \u0447\u0438\u0441\u0435\u043b.  * @param z1 \u0414\u0435\u043b\u0438\u043c\u043e\u0435.  * @param z2 \u0414\u0435\u043b\u0438\u0442\u0435\u043b\u044c.  * @return \u0423\u0441\u043f\u0435\u0445\/\u043d\u0435\u0443\u0434\u0430\u0447\u0430. *\/ bool test_div(U128 z1, U128 z2, PythonCaller&amp; caller) {     const U128 z3 = z1 \/ z2;     PyObject* quotient = caller.Divide(z1, z2);     return caller.Compare(quotient, z3.value().c_str()); }  \/**  * \u041f\u043e\u043b\u0443\u0441\u043b\u0443\u0447\u0430\u0439\u043d\u044b\u0439 \u0442\u0435\u0441\u0442 \u0434\u0435\u043b\u0435\u043d\u0438\u044f 128-\u0431\u0438\u0442\u043d\u044b\u0445 \u0447\u0438\u0441\u0435\u043b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u043d\u044b\u0439 \u043d\u0430\u0431\u043e\u0440 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u0432\u0431\u043b\u0438\u0437\u0438 \u0443\u0433\u043b\u043e\u0432\u044b\u0445 \u0438 \u0433\u0440\u0430\u043d\u0438\u0447\u043d\u044b\u0445.  * @param N \u041a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0432\u043d\u0435\u0448\u043d\u0438\u0445 \u0438\u0442\u0435\u0440\u0430\u0446\u0438\u0439. *\/ void test_division_semi_randomly(long long N) {     if (N &lt; 1) {         std::cout &lt;&lt; \"Skipped!\\n\";         return;     }     PythonCaller caller;     const std::vector&lt;u64> choice {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10,                                      65535, 65534, 65533, 65532, 65531, 65530,                                      16384, 16383, 16382, 16385, 16386, 16387, 16388,                                      -1ull, -2ull, -3ull, -4ull, -5ull, -6ull, -7ull};     auto make_test = [&amp;caller](const Quadrupole q, const Signess s) -> bool {         return test_div(U128{.mHigh = q.A, .mLow = q.B, .mSign = s.s1},                         U128{.mHigh = q.C, .mLow = q.D, .mSign = s.s2},                         caller);     };     auto get_quadrupole = [&amp;choice]() -> Quadrupole {         auto idx1 = roll_uint() % choice.size();         auto idx2 = roll_uint() % choice.size();         auto idx3 = roll_uint() % choice.size();         auto idx4 = roll_uint() % choice.size();         Quadrupole q {choice[idx1], choice[idx2], choice[idx3], choice[idx4]};         return q;     };     long long counter = 0;     long long external_iterations = 0;     bool is_ok = true;     while (external_iterations &lt; N) {         ++counter;         const Quadrupole q = get_quadrupole();         const Signess s{roll_bool(), roll_bool()};         if (q.C == 0 &amp;&amp; q.D == 0) {             continue;         }         is_ok &amp;= make_test(q, s);         assert(is_ok);         if (counter % (1ll &lt;&lt; 20) == 0) {             external_iterations++;             std::cout &lt;&lt; \"... iterations: \" &lt;&lt; counter &lt;&lt; \". External: \" &lt;&lt;                  external_iterations &lt;&lt; \" from \" &lt;&lt; N &lt;&lt; '\\n';         }     } }  \/**  * \u0421\u043b\u0443\u0447\u0430\u0439\u043d\u044b\u0439 \u0442\u0435\u0441\u0442 \u0434\u0435\u043b\u0435\u043d\u0438\u044f 128-\u0431\u0438\u0442\u043d\u044b\u0445 \u0447\u0438\u0441\u0435\u043b.  * @param N \u041a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0432\u043d\u0435\u0448\u043d\u0438\u0445 \u0438\u0442\u0435\u0440\u0430\u0446\u0438\u0439. *\/ void test_division_randomly(long long N) {     if (N &lt; 1) {         std::cout &lt;&lt; \"Skipped!\\n\";         return;     }     PythonCaller caller;     auto make_test = [&amp;caller](const Quadrupole q, const Signess s) -> bool {         return test_div(U128{.mHigh = q.A, .mLow = q.B, .mSign = s.s1},                         U128{.mHigh = q.C, .mLow = q.D, .mSign = s.s2},                         caller);     };     auto get_quadrupole = []() -> Quadrupole {         Quadrupole q {roll_ulow(), roll_ulow(), roll_ulow(), roll_ulow()};         return q;     };     long long counter = 0;     long long external_iterations = 0;     bool is_ok = true;     while (external_iterations &lt; N) {         ++counter;         const Quadrupole q = get_quadrupole();         const Signess s{roll_bool(), roll_bool()};         if (q.C == 0 &amp;&amp; q.D == 0) {             continue;         }         is_ok &amp;= make_test(q, s);         assert(is_ok);         if (counter % (1ll &lt;&lt; 20) == 0) {             external_iterations++;             std::cout &lt;&lt; \"... iterations: \" &lt;&lt; counter &lt;&lt; \". External: \" &lt;&lt;                  external_iterations &lt;&lt; \" from \" &lt;&lt; N &lt;&lt; '\\n';         }     } }   int main(int argc, char* argv[]) {     long long N = 10;     if (argc > 1) {         N = atoi(argv[1]);         std::cout &lt;&lt; \"You set the number of external iterations N: \" &lt;&lt; N &lt;&lt; '\\n';     }     std::cout &lt;&lt; \"Run semi-random test...\\n\";     test_division_semi_randomly(N);     std::cout &lt;&lt; \"Ok\\n\";      std::cout &lt;&lt; \"Run random test...\\n\";     test_division_randomly(N);     std::cout &lt;&lt; \"Ok\\n\";     return 0; }<\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<p>\u0417\u0434\u0435\u0441\u044c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442\u0441\u044f \u0442\u0435\u0441\u0442\u044b \u0434\u0432\u0443\u0445 \u0442\u0438\u043f\u043e\u0432:<\/p>\n<ol>\n<li>\n<p>\u041f\u043e\u043b\u0443-\u0441\u043b\u0443\u0447\u0430\u0439\u043d\u044b\u0439 \u0442\u0435\u0441\u0442,<\/p>\n<\/li>\n<li>\n<p>\u0421\u043b\u0443\u0447\u0430\u0439\u043d\u044b\u0439 \u0442\u0435\u0441\u0442.<\/p>\n<\/li>\n<\/ol>\n<p>\u041f\u043e\u043b\u0443-\u0441\u043b\u0443\u0447\u0430\u0439\u043d\u044b\u0439 \u0442\u0435\u0441\u0442 \u043f\u0440\u043e\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u043f\u043e \u0433\u0440\u0430\u043d\u0438\u0447\u043d\u044b\u043c \u0438 \u0443\u0433\u043b\u043e\u0432\u044b\u043c \u0441\u043b\u0443\u0447\u0430\u044f\u043c \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c\u043e\u0433\u043e \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0430 \u0438 \u0437\u0430\u0432\u0435\u0440\u0448\u0430\u0435\u0442\u0441\u044f, \u0447\u0442\u043e \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043e\u0442\u043d\u043e\u0441\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0431\u044b\u0441\u0442\u0440\u043e \u0432\u044b\u044f\u0432\u0438\u0442\u044c \u0438\u0437\u044a\u044f\u043d\u044b \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0430. \u0421\u043b\u0443\u0447\u0430\u0439\u043d\u044b\u0439 \u0436\u0435 \u0442\u0435\u0441\u0442 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043f\u0440\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u0432 \u0442\u043e\u043c \u0447\u0438\u0441\u043b\u0435 \u0438 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043e\u0442\u043b\u0438\u0447\u043d\u044b\u0435 \u043e\u0442 \u0433\u0440\u0430\u043d\u0438\u0447\u043d\u044b\u0445 \u0441\u043b\u0443\u0447\u0430\u0435\u0432.<\/p>\n<p>\u0420\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f 128-\u0431\u0438\u0442\u043d\u044b\u0445 \u0447\u0438\u0441\u0435\u043b <em>U128<\/em> \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u0430 \u043d\u0438\u0436\u0435.<\/p>\n<details class=\"spoiler\">\n<summary>\u0421\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430 U128<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"cpp\">static constexpr char DIGITS[10]{'0', '1', '2', '3', '4',                                  '5', '6', '7', '8', '9'};  \/\/ High\/Low \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430 128-\u0431\u0438\u0442\u043d\u043e\u0433\u043e \u0447\u0438\u0441\u043b\u0430 \u0441\u043e \u0437\u043d\u0430\u043a\u043e\u043c \u0438 \u0444\u043b\u0430\u0433\u043e\u043c \u043f\u0435\u0440\u0435\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f. \/\/ \u0414\u043b\u044f \u0438\u043b\u043b\u044e\u0441\u0442\u0440\u0430\u0446\u0438\u0438 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0430 \u0434\u0435\u043b\u0435\u043d\u0438\u044f \u0434\u0432\u0443\u0445 U128 \u0447\u0438\u0441\u0435\u043b \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d\u044b \u043e\u0441\u043d\u043e\u0432\u043d\u044b\u0435 \/\/ \u0430\u0440\u0438\u0444\u043c\u0435\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u044b, \u043a\u0440\u043e\u043c\u0435 \u0443\u043c\u043d\u043e\u0436\u0435\u043d\u0438\u044f \u0434\u0432\u0443\u0445 U128 \u0447\u0438\u0441\u0435\u043b. struct U128 {     \/\/ \u0411\u0438\u0442\u043e\u0432\u0430\u044f \u043f\u043e\u043b\u0443\u0448\u0438\u0440\u0438\u043d\u0430 \u043f\u043e\u043b\u043e\u0432\u0438\u043d\u043e\u043a.     static constexpr int mHalfWidth = (sizeof(ULOW) * CHAR_BIT) \/ 2;     \/\/ \u041d\u0430\u0438\u0431\u043e\u043b\u044c\u0448\u0435\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043f\u043e\u043b\u043e\u0432\u0438\u043d\u043e\u043a, M-1.     static constexpr ULOW mMaxULOW = ULOW(-1);     ULOW mHigh = 0;     ULOW mLow = 0;     bool mSign = 0;     bool mOverflow = 0;  bool is_zero() const {     return (mLow | mHigh | mOverflow) == 0; }  bool is_negative() const {     return mSign; }  bool is_non_negative() const {     return !mSign &amp;&amp; !mOverflow; }  bool is_nonzero_negative() const {     return (mLow | mHigh) &amp;&amp; mSign &amp;&amp; !mOverflow; }  bool is_overflow() const {     return mOverflow; }  constexpr static U128 get_zero() {     return U128 {.mHigh = 0, .mLow = 0, .mSign = 0, .mOverflow = 0}; }  constexpr static U128 get_unit() {     return U128 {.mHigh = 0, .mLow = 1, .mSign = 0, .mOverflow = 0}; }  constexpr static U128 get_unit_neg() {     return U128 {.mHigh = 0, .mLow = 1, .mSign = 1, .mOverflow = 0}; }  U128 operator+(U128 rhs) const {     U128 result{};     U128 X = *this;     if (X.is_negative() &amp;&amp; !rhs.is_negative()) {         X.mSign = 0;         result = rhs - X;         return result;     }     if (!X.is_negative() &amp;&amp; rhs.is_negative()) {         rhs.mSign = 0;         result = X - rhs;         return result;     }     result.mLow = X.mLow + rhs.mLow;     const ULOW c1 = result.mLow &lt; std::min(X.mLow, rhs.mLow);     result.mHigh = X.mHigh + rhs.mHigh;     const int c2 = result.mHigh &lt; std::min(X.mHigh, rhs.mHigh);     ULOW tmp = result.mHigh;     result.mHigh = tmp + c1;     const int c3 = result.mHigh &lt; std::min(tmp, c1);     result.mOverflow = c2 || c3;     if (X.mSign &amp;&amp; rhs.mSign) {         result.mSign = 1;     }     return result; }  U128&amp; operator+=(U128 other) {     *this = *this + other;     return *this; }  U128 operator-(U128 rhs) const {     U128 result{};     U128 X = *this;     if (X.is_negative() &amp;&amp; !rhs.is_negative()) {         rhs.mSign = 1;         result = rhs + X;         return result;     }     if (!X.is_negative() &amp;&amp; rhs.is_negative()) {         rhs.mSign = 0;         result = X + rhs;         return result;     }     if (X.is_negative() &amp;&amp; rhs.is_negative()) {         rhs.mSign = 0;         X.mSign = 0;         result = rhs - X;         return result;     }     if (X.is_zero()) {         result = rhs;         result.mSign = rhs.mSign ^ 1;         return result;     }     result.mLow = X.mLow - rhs.mLow;     result.mHigh = X.mHigh - rhs.mHigh;     const bool borrow = X.mLow &lt; rhs.mLow;     const bool hasUnit = X.mHigh > rhs.mHigh;     if (borrow &amp;&amp; hasUnit) {         result.mHigh -= ULOW(1);     }     if (borrow &amp;&amp; !hasUnit) {         result = rhs - X;         result.mSign ^= 1;         return result;     }     if (!borrow &amp;&amp; X.mHigh &lt; rhs.mHigh) {         result.mHigh = -result.mHigh - ULOW(result.mLow != 0);         result.mLow = -result.mLow;         result.mSign = 1;     }     return result; }  U128&amp; operator-=(U128 other) {     *this = *this - other;     return *this; }  U128 mult64(ULOW x, ULOW y) const {     constexpr ULOW MASK = (ULOW(1) &lt;&lt; mHalfWidth) - 1;     const ULOW x_low = x &amp; MASK;     const ULOW y_low = y &amp; MASK;     const ULOW x_high = x >> mHalfWidth;     const ULOW y_high = y >> mHalfWidth;     const ULOW t1 = x_low * y_low;     const ULOW t = t1 >> mHalfWidth;     const ULOW t21 = x_low * y_high;     const ULOW q = t21 >> mHalfWidth;     const ULOW p = t21 &amp; MASK;     const ULOW t22 = x_high * y_low;     const ULOW s = t22 >> mHalfWidth;     const ULOW r = t22 &amp; MASK;     const ULOW t3 = x_high * y_high;     U128 result{};     result.mLow = t1;     const ULOW div = (q + s) + ((p + r + t) >> mHalfWidth);     const ULOW mod = (t21 &lt;&lt; mHalfWidth) + (t22 &lt;&lt; mHalfWidth);     result.mLow += mod;     result.mHigh += div;     result.mHigh += t3;     result.mOverflow = result.mHigh &lt; t3 ? 1 : 0;     return result; }  U128 operator*(ULOW rhs) const {     U128 result = mult64(mLow, rhs);     U128 tmp = mult64(mHigh, rhs);     tmp.mHigh = tmp.mLow;     tmp.mLow = 0;     result += tmp;     result.mSign = !result.is_zero() ? this->mSign : 0;     return result; }  U128 div10() const { \/\/ \u0421\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u044b\u0439 \u043c\u0435\u0442\u043e\u0434 \u0434\u0435\u043b\u0435\u043d\u0438\u044f \u043d\u0430 10 \u0434\u043b\u044f \u0441\u0442\u0440\u043e\u043a\u043e\u0432\u043e\u0433\u043e \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0447\u0438\u0441\u043b\u0430.     U128 X = *this;     const int sign = X.mSign;     X.mSign = 0;     ULOW Q = X.mHigh \/ 10;     ULOW R = X.mHigh % 10;     ULOW N = R * (mMaxULOW \/ 10) + (X.mLow \/ 10);     U128 result{.mHigh = Q, .mLow = N};     U128 E = X - result * 10;     while (E.mHigh != 0 || E.mLow >= 10) {         Q = E.mHigh \/ 10;         R = E.mHigh % 10;         N = R * (mMaxULOW \/ 10) + (E.mLow \/ 10);         const U128 tmp {.mHigh = Q, .mLow = N};         result += tmp;         E -= tmp * 10;     }     result.mSign = sign;     return result; }  U128 operator\/(ULOW y) const {     assert(y != 0);     const U128 X = *this;     ULOW Q = X.mHigh \/ y;     ULOW R = X.mHigh % y;     ULOW N = R * (mMaxULOW \/ y) + (X.mLow \/ y);     U128 result{.mHigh = Q, .mLow = N, .mSign = X.mSign};     U128 E = X - result * y; \/\/ \u041e\u0448\u0438\u0431\u043a\u0430 \u043e\u0442 \u0434\u0435\u043b\u0435\u043d\u0438\u044f: \u043e\u0441\u0442\u0430\u0442\u043e\u043a \u043e\u0442 \u0434\u0435\u043b\u0435\u043d\u0438\u044f.     while (1) {         Q = E.mHigh \/ y;         R = E.mHigh % y;         N = R * (mMaxULOW \/ y) + (E.mLow \/ y);         const U128 tmp {.mHigh = Q, .mLow = N, .mSign = E.mSign};         if (tmp.is_zero()) {             break;         }         result += tmp;         E -= tmp * y;     }     if (E.is_nonzero_negative()) {         result -= get_unit();         E += U128{.mHigh = 0, .mLow = y};     }     return result; }  U128&amp; operator\/=(ULOW y) {     *this = *this \/ y;     return *this; }  U128 operator\/(const U128 other) const {     U128 X = *this;     U128 Y = other;     constexpr U128 ZERO = get_zero();     constexpr U128 UNIT = get_unit();     constexpr U128 UNIT_NEG = get_unit_neg();     if (Y.mHigh == 0) {         X.mSign ^= Y.mSign;         U128 result = X \/ Y.mLow;         return result;     }     const bool make_sign_inverse = X.mSign != Y.mSign;     X.mSign = make_sign_inverse;     Y.mSign = 0;     const ULOW Q = X.mHigh \/ Y.mHigh;     const ULOW R = X.mHigh % Y.mHigh;     const ULOW Delta = mMaxULOW - Y.mLow;     const U128 DeltaQ = mult64(Delta, Q);     U128 W1 = U128{.mHigh = R, .mLow = 0} - U128{.mHigh = Q, .mLow = 0};     W1 = W1 + DeltaQ;     const ULOW C1 = (Y.mHigh &lt; mMaxULOW) ? Y.mHigh + ULOW(1) : mMaxULOW;     const ULOW W2 = mMaxULOW - Delta \/ C1;     U128 Quotient = W1 \/ W2;     Quotient = Quotient \/ C1;     U128 result = U128{.mHigh = 0, .mLow = Q} + Quotient;     assert(result.mHigh == 0);     result.mSign ^= make_sign_inverse;     U128 N = Y * result.mLow;     N.mSign ^= make_sign_inverse;     assert(!N.is_overflow());     U128 Error = X - N;     U128 More = Error - Y;     bool do_inc = More.is_non_negative();     bool do_dec = Error.is_nonzero_negative();     while (do_dec || do_inc) {         result += (do_inc ? UNIT : (do_dec ? UNIT_NEG : ZERO));         if (do_dec) {             Error += Y;         }         if (do_inc) {             Error -= Y;         }         More = Error - Y;         do_inc = More.is_non_negative();         do_dec = Error.is_nonzero_negative();     }     return result; }  \/**  * \u0412\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0441\u0442\u0440\u043e\u043a\u043e\u0432\u043e\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0447\u0438\u0441\u043b\u0430.  *\/ std::string value() const {     std::string result{};     if (this->is_overflow()) {         result = \"Overflow\";         return result;     }     U128 X = *this;     constexpr int multiplier_mod10 = mMaxULOW % 10 + 1;     while (!X.is_zero()) {         const int d =             ((X.mLow % 10) + multiplier_mod10 * (X.mHigh % 10)) % 10;         result.push_back(DIGITS[d]);         X = X.div10();     }     if (this->is_negative() &amp;&amp; !this->is_zero()) {         result.push_back('-');     }     std::reverse(result.begin(), result.end());     return result.length() != 0 ? result : \"0\"; } };<\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<h3>\u0412\u044b\u0432\u043e\u0434\u044b<\/h3>\n<p>\u041f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u044b \u0421++ \u0442\u0435\u0441\u0442\u044b \u0434\u0435\u043b\u0435\u043d\u0438\u044f 128-\u0431\u0438\u0442\u043d\u044b\u0445 \u0447\u0438\u0441\u0435\u043b, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0449\u0438\u0435 Python C API \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 \u0434\u043b\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u044d\u0442\u0430\u043b\u043e\u043d\u043d\u044b\u0445 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439.<\/p>\n<p>\u041f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u044b \u0448\u0430\u0433\u0438 \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438 \u0441\u0440\u0435\u0434\u044b \u0438 \u043f\u0440\u043e\u0435\u043a\u0442\u0430 \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c WSL Ubuntu 22.04 \u0438 Visual Studio Code.<\/p>\n<\/p>\n<\/div>\n<\/div>\n<\/div>\n<p><!----><!----><\/div>\n<p><!----><!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/articles\/813751\/\"> https:\/\/habr.com\/ru\/articles\/813751\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<h3>\u0412\u0432\u0435\u0434\u0435\u043d\u0438\u0435<\/h3>\n<p>\u0420\u0430\u043d\u0435\u0435 \u0431\u044b\u043b \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0439 <a href=\"https:\/\/habr.com\/ru\/articles\/811323\/\" rel=\"noopener noreferrer nofollow\">\u0410\u043b\u0433\u043e\u0440\u0438\u0442\u043c<\/a> \u0434\u0435\u043b\u0435\u043d\u0438\u044f 2W-\u0431\u0438\u0442\u043e\u0432\u044b\u0445 \u0447\u0438\u0441\u0435\u043b \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0439 \u043d\u0430\u0434 W-\u0431\u0438\u0442\u043e\u0432\u044b\u043c\u0438 \u0447\u0438\u0441\u043b\u0430\u043c\u0438. \u0414\u043b\u044f \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b\u0438\u0441\u044c \u0446\u0435\u043b\u044b\u0435 \u0447\u0438\u0441\u043b\u0430 \u044f\u0437\u044b\u043a\u0430 \u0421++, \u0447\u0442\u043e \u043d\u0435 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u043b\u043e \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0442\u044c, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, 128-\u0431\u0438\u0442\u043d\u044b\u0435 \u0446\u0435\u043b\u044b\u0435 \u0447\u0438\u0441\u043b\u0430. \u041e\u0434\u043d\u0430\u043a\u043e, \u0432 \u044f\u0437\u044b\u043a Python \u0432\u0441\u0442\u0440\u043e\u0435\u043d\u0430 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0430 \u0446\u0435\u043b\u044b\u0445 \u0447\u0438\u0441\u0435\u043b \u043d\u0435\u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u043d\u043e\u0439 \u0448\u0438\u0440\u0438\u043d\u044b (Big Integer), \u0430 \u0442\u0430\u043a\u0436\u0435 \u0438\u043c\u0435\u0435\u0442\u0441\u044f API \u0434\u043b\u044f \u0432\u044b\u0437\u043e\u0432\u0430 \u043c\u0435\u0442\u043e\u0434\u043e\u0432 Python \u0438\u0437 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c \u043d\u0430 \u044f\u0437\u044b\u043a\u0435 \u0421\/\u0421++. \u042d\u0442\u043e \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043f\u0440\u043e\u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0440\u0430\u0437\u043d\u044b\u0435 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u044b \u0441 \u0447\u0438\u0441\u043b\u0430\u043c\u0438, \u0432 \u0442\u043e\u043c \u0447\u0438\u0441\u043b\u0435 \u0434\u0435\u043b\u0435\u043d\u0438\u0435, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0430 \u0441\u0442\u0440\u043e\u043a\u043e\u0432\u043e\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0447\u0438\u0441\u0435\u043b.<\/p>\n<p>\u0412 \u0434\u0430\u043d\u043d\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u0440\u0430\u0441\u043f\u0438\u0441\u0430\u043d\u044b \u0448\u0430\u0433\u0438 \u0434\u043b\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f Python C API \u0432 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0435 \u043d\u0430 \u044f\u0437\u044b\u043a\u0435 \u0421++, \u0430 \u0442\u0430\u043a\u0436\u0435 \u043f\u043e\u043a\u0430\u0437\u0430\u043d \u043f\u0440\u0438\u043c\u0435\u0440 \u0432\u044b\u0437\u043e\u0432\u0430 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u0430 \u0434\u0435\u043b\u0435\u043d\u0438\u044f \u0434\u0432\u0443\u0445 \u0446\u0435\u043b\u044b\u0445 \u0447\u0438\u0441\u0435\u043b \u0441 \u0432\u043e\u0437\u0432\u0440\u0430\u0442\u043e\u043c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0430 \u0432 \u0432\u0438\u0434\u0435 \u0441\u0442\u0440\u043e\u043a\u0438 \u0421. \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b\u0430\u0441\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0430\u044f \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u043d\u0430\u044f \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u044f:<\/p>\n<ul>\n<li>\n<p>Windows 11, WSL Ubuntu 22.04.3 LTS, GCC 12.3.0.<\/p>\n<\/li>\n<li>\n<p>IDE Visual Studio Code \u0430\u043a\u0442\u0443\u0430\u043b\u044c\u043d\u043e\u0439 \u0432\u0435\u0440\u0441\u0438\u0438.<\/p>\n<\/li>\n<li>\n<p>\u0412\u0441\u0442\u0440\u043e\u0435\u043d\u043d\u044b\u0439 \u0432 Ubuntu Python 3.10.<\/p>\n<\/li>\n<\/ul>\n<h3>\u041d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0430 \u0441\u0440\u0435\u0434\u044b<\/h3>\n<p>\u041f\u0440\u0435\u0434\u0432\u0430\u0440\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c \u043d\u0430\u0431\u043e\u0440 <em>build-essential<\/em> \u0438 \u0441\u0440\u0435\u0434\u0441\u0442\u0432\u043e \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0430 <em>python3-dev<\/em>.<\/p>\n<ol>\n<li>\n<p>\u041e\u0442\u043a\u0440\u044b\u0432\u0430\u0435\u043c \u043a\u043e\u043d\u0441\u043e\u043b\u044c <em>Ubuntu<\/em> \u0438 \u0441\u043e\u0437\u0434\u0430\u0435\u043c \u0434\u0438\u0440\u0435\u043a\u0442\u043e\u0440\u0438\u044e \u0441 \u043f\u0440\u043e\u0435\u043a\u0442\u043e\u043c:<\/p>\n<\/li>\n<\/ol>\n<pre><code class=\"bash\">mkdir division_test<\/code><\/pre>\n<ol start=\"2\">\n<li>\n<p>\u041f\u0435\u0440\u0435\u0445\u043e\u0434\u0438\u043c \u0432 \u0441\u043e\u0437\u0434\u0430\u043d\u043d\u044b\u0439 \u043a\u0430\u0442\u0430\u043b\u043e\u0433 \u0438 \u0441\u043e\u0437\u0434\u0430\u0435\u043c \u0442\u043e\u0447\u043a\u0443 \u0432\u0445\u043e\u0434\u0430 \u0432 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0443:<\/p>\n<\/li>\n<\/ol>\n<pre><code class=\"bash\">cd division_test touch main.cpp<\/code><\/pre>\n<ol start=\"3\">\n<li>\n<p>\u0417\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u043c IDE Visual Studio Code. \u0423\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u043c \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u044f WSL \u0438 C\/C++.<\/p>\n<\/li>\n<li>\n<p>\u041f\u0435\u0440\u0435\u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u043c Visual Studio Code, \u0438 \u0447\u0435\u0440\u0435\u0437 IDE \u043e\u0442\u043a\u0440\u044b\u0432\u0430\u0435\u043c <strong>\u0434\u0438\u0440\u0435\u043a\u0442\u043e\u0440\u0438\u044e<\/strong> \u0441\u043e\u0437\u0434\u0430\u043d\u043d\u043e\u0433\u043e \u043f\u0440\u043e\u0435\u043a\u0442\u0430, <em>division_test<\/em>. \u0412 \u0438\u0442\u043e\u0433\u0435, \u043d\u0430 \u043f\u0430\u043d\u0435\u043b\u0438 EXPLORER \u0434\u043e\u043b\u0436\u0435\u043d \u043e\u0442\u043e\u0431\u0440\u0430\u0437\u0438\u0442\u044c\u0441\u044f \u0444\u0430\u0439\u043b <em>main.cpp<\/em>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043d\u0430\u0434\u043e \u043e\u0442\u043a\u0440\u044b\u0442\u044c \u0434\u043b\u044f \u0440\u0435\u0434\u0430\u043a\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f.<\/p>\n<\/li>\n<li>\n<p>\u041a\u043e\u043f\u0438\u0440\u0443\u0435\u043c\/\u0441\u043e\u0437\u0434\u0430\u0435\u043c \u0442\u0435\u0441\u0442\u043e\u0432\u044b\u0439 \u0438\u0441\u0445\u043e\u0434\u043d\u044b\u0439 \u043a\u043e\u0434.<\/p>\n<\/li>\n<li>\n<p>\u0427\u0435\u0440\u0435\u0437 \u043c\u0435\u043d\u044e IDE \u00abTerminal\/Configure Default Build Task&#8230;\u00bb \u0441\u043e\u0437\u0434\u0430\u0435\u043c \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u044e \u0441\u0431\u043e\u0440\u043a\u0438 <em>tasks.json<\/em>.<\/p>\n<\/li>\n<li>\n<p>\u0412 \u0444\u0430\u0439\u043b \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0438 <em>tasks.json<\/em> \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u043b\u0438\u043d\u043a\u043e\u0432\u043a\u0443 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 Python, \u0430 \u0442\u0430\u043a\u0436\u0435 \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u043e\u043f\u0446\u0438\u0438: \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442 \u0421++20 \u0438 \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u044e \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0446\u0438\u0438 O3:<\/p>\n<\/li>\n<\/ol>\n<pre><code class=\"json\">... \"args\": [     \"-fdiagnostics-color=always\",     \"-O3\",     \"-std=c++20\",     \"${file}\",     \"-o\",     \"${fileDirname}\/${fileBasenameNoExtension}\",     \"-lpython3.10\" ], ...<\/code><\/pre>\n<ol start=\"8\">\n<li>\n<p>\u0410\u043a\u0442\u0438\u0432\u0438\u0440\u0443\u0435\u043c \u0442\u043e\u0447\u043a\u0443 \u0432\u0445\u043e\u0434\u0430: \u0444\u0430\u0439\u043b <em>main.cpp<\/em>. \u041f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043e\u0447\u043d\u043e\u0433\u043e \u0444\u0430\u0439\u043b\u0430 Python<\/p>\n<\/li>\n<\/ol>\n<pre><code class=\"cpp\">#include &lt;python3.10\/Python.h><\/code><\/pre>\n<ol start=\"9\">\n<li>\n<p>\u041e\u0442\u043a\u0440\u044b\u0432\u0430\u0435\u043c \u0442\u0435\u0440\u043c\u0438\u043d\u0430\u043b \u00abTerminal\/New Terminal\u00bb, \u0430\u043a\u0442\u0438\u0432\u0438\u0440\u0443\u0435\u043c \u0444\u043e\u043a\u0443\u0441 (\u043a\u0443\u0440\u0441\u043e\u0440) \u043d\u0430\u00a0\u0442\u0435\u0440\u043c\u0438\u043d\u0430\u043b\u0435 \u0438 \u043d\u0430\u0436\u0438\u043c\u0430\u0435\u043c \u00abCtrl+Shift+B\u00bb, \u043d\u0435\u00a0\u0437\u0430\u0431\u044b\u0432 \u043f\u0435\u0440\u0435\u043a\u043b\u044e\u0447\u0438\u0442\u044c\u0441\u044f \u043d\u0430\u00a0\u0430\u043d\u0433\u043b\u0438\u0439\u0441\u043a\u0438\u0439 \u044f\u0437\u044b\u043a EN. \u041f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0430 \u0434\u043e\u043b\u0436\u043d\u0430 \u0441\u043e\u0431\u0440\u0430\u0442\u044c\u0441\u044f. \u0417\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u044c \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0443 \u043c\u043e\u0436\u043d\u043e \u0432 \u0442\u0435\u0440\u043c\u0438\u043d\u0430\u043b\u0435 \u043a\u0430\u043a \u043e\u0431\u044b\u0447\u043d\u043e: <strong>.\/main<\/strong>.<\/p>\n<\/li>\n<\/ol>\n<h3>\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 API C Python<\/h3>\n<p>\u041f\u043e\u0441\u043b\u0435 \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438 \u0441\u0440\u0435\u0434\u044b \u0438 \u0441\u0431\u043e\u0440\u043a\u0438 \u0442\u0435\u0441\u0442\u043e\u0432\u043e\u0433\u043e \u043f\u0440\u043e\u0435\u043a\u0442\u0430 \u043c\u043e\u0436\u043d\u043e \u0441\u0432\u043e\u0431\u043e\u0434\u043d\u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u043c\u0435\u0442\u043e\u0434\u0430\u043c\u0438 API C Python.<\/p>\n<p>\u0414\u043b\u044f \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0434\u0435\u043b\u0435\u043d\u0438\u044f \u0434\u0432\u0443\u0445 128-\u0431\u0438\u0442\u043d\u044b\u0445 \u0447\u0438\u0441\u0435\u043b \u0431\u044b\u043b \u0441\u043e\u0437\u0434\u0430\u043d \u0432\u0441\u043f\u043e\u043c\u043e\u0433\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u043a\u043b\u0430\u0441\u0441 <em>PythonCaller<\/em>.<\/p>\n<details class=\"spoiler\">\n<summary>\u0412\u0441\u043f\u043e\u043c\u043e\u0433\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u043a\u043b\u0430\u0441\u0441 \u0434\u0435\u043b\u0435\u043d\u0438\u044f \u0447\u0438\u0441\u0435\u043b \u043d\u0430 API C Python<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"cpp\">class PythonCaller { public:      PythonCaller() {         Py_Initialize();         mMain = PyImport_AddModule(\"__main__\");         mGlobalDictionary = PyModule_GetDict(mMain);         mLocalDictionary = PyDict_New();         std::cout &lt;&lt; \"Python was initialized!\\n\";     }      ~PythonCaller() {         Py_Finalize();         std::cout &lt;&lt; \"~Python was finalized!\\n\";     }      \/**      * \u0414\u0435\u043b\u0438\u0442 \u0434\u0432\u0430 128-\u0431\u0438\u0442\u043d\u044b\u0445 \u0447\u0438\u0441\u043b\u0430.      * @param X \u0414\u0435\u043b\u0438\u043c\u043e\u0435.      * @param Y \u0414\u0435\u043b\u0438\u0442\u0435\u043b\u044c.      * @return \u0427\u0430\u0441\u0442\u043d\u043e\u0435 \u043e\u0442 \u0434\u0435\u043b\u0435\u043d\u0438\u044f, \u043e\u0431\u044a\u0435\u043a\u0442 Python.     *\/     PyObject* Divide(U128 X, U128 Y) const {         const char* pythonScript = \"quotient = nominator \/\/ denominator\\n\";         PyDict_SetItemString(mLocalDictionary, \"nominator\", PyLong_FromString(X.value().c_str(), nullptr, 10));         PyDict_SetItemString(mLocalDictionary, \"denominator\", PyLong_FromString(Y.value().c_str(), nullptr, 10));         PyRun_String(pythonScript, Py_file_input, mGlobalDictionary, mLocalDictionary);         return PyDict_GetItemString(mLocalDictionary, \"quotient\");     }     \/**      * \u0421\u0440\u0430\u0432\u043d\u0438\u0432\u0430\u0435\u0442 \u0434\u0432\u0430 \u0447\u0430\u0441\u0442\u043d\u044b\u0445 \u043e\u0442 \u0434\u0435\u043b\u0435\u043d\u0438\u044f.      * @param quotient \u0427\u0430\u0441\u0442\u043d\u043e\u0435 \u043e\u0442 \u0434\u0435\u043b\u0435\u043d\u0438\u044f Python, \u043e\u0431\u044a\u0435\u043a\u0442 Python.      * @param reference \u0427\u0430\u0441\u0442\u043d\u043e\u0435 \u043e\u0442 \u0434\u0435\u043b\u0435\u043d\u0438\u044f \u0421++, \u0441\u0442\u0440\u043e\u043a\u0430.     *\/     bool Compare(PyObject* quotient, const char* reference) const {         PyObject* repr = PyObject_Repr(quotient);         PyObject* str = PyUnicode_AsEncodedString(repr, \"utf-8\", \"~E~\");         const char *bytes = PyBytes_AsString(str);         const bool is_ok = strcmp(bytes, reference) == 0;         if (!is_ok) {             printf(\"Python: %s\\n\", bytes);             printf(\"C++: %s\\n\", reference);         }         Py_XDECREF(repr);         Py_XDECREF(str);         return is_ok;     } private:      PyObject* mMain = nullptr;     PyObject* mGlobalDictionary = nullptr;     PyObject* mLocalDictionary = nullptr; };<\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<p>\u0412 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u0435 \u043a\u043b\u0430\u0441\u0441\u0430 \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u0441\u0440\u0435\u0434\u0430 Python \u0441 \u0432\u0441\u043f\u043e\u043c\u043e\u0433\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u043c\u0438 \u0441\u043b\u043e\u0432\u0430\u0440\u044f\u043c\u0438 \u0434\u043b\u044f \u0432\u0432\u043e\u0434\u0430-\u0432\u044b\u0432\u043e\u0434\u0430 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u043e\u0432 \u0441\u0447\u0435\u0442\u0430.<\/p>\n<p>\u0414\u043b\u044f \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0438 \u0434\u043b\u0438\u043d\u043d\u043e\u0433\u043e Python \u0447\u0438\u0441\u043b\u0430 \u0442\u0438\u043f\u0430 <em>int<\/em> \u0438\u0437 \u0421++ \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f API \u043c\u0435\u0442\u043e\u0434 <em>PyLong_FromString<\/em>, \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u044e\u0449\u0438\u0439 \u0441\u0442\u0440\u043e\u043a\u043e\u0432\u043e\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0447\u0438\u0441\u043b\u0430 (const char*, \u043f\u0435\u0440\u0432\u044b\u0439 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442) \u0438 \u043e\u0441\u043d\u043e\u0432\u0430\u043d\u0438\u0435 \u0441\u0438\u0441\u0442\u0435\u043c\u044b \u0441\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f (\u0442\u0440\u0435\u0442\u0438\u0439 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442). \u0421\u043a\u0440\u0438\u043f\u0442 Python \u0441\u043e\u0437\u0434\u0430\u0435\u0442\u0441\u044f \u0432 \u0432\u0438\u0434\u0435 \u0441\u0442\u0440\u043e\u043a\u0438 \u0441 \u043d\u0435\u043f\u043e\u0441\u0440\u0435\u0434\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0439 \u0437\u0430\u043f\u0438\u0441\u044c\u044e \u0434\u0435\u043b\u0435\u043d\u0438\u044f \u0447\u0435\u0440\u0435\u0437 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435, \u0438\u043c\u0435\u043d\u0430 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0441\u043e\u0432\u043f\u0430\u0434\u0430\u044e\u0442 \u0441 \u043a\u043b\u044e\u0447\u0430\u043c\u0438 \u043e\u0431\u043c\u0435\u043d\u043d\u043e\u0433\u043e \u0441\u043b\u043e\u0432\u0430\u0440\u044f <em>mLocalDictionary<\/em>. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0434\u0435\u043b\u0435\u043d\u0438\u044f (\u0447\u0430\u0441\u0442\u043d\u043e\u0435) \u0431\u0443\u0434\u0435\u0442 \u0434\u043e\u0441\u0442\u0443\u043f\u0435\u043d \u043f\u043e \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0435\u043c\u0443 \u043a\u043b\u044e\u0447\u0443 \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u0447\u0435\u0440\u0435\u0437 API \u043c\u0435\u0442\u043e\u0434 <em>PyDict_GetItemString<\/em> \u0432 \u0432\u0438\u0434\u0435 Python \u043e\u0431\u044a\u0435\u043a\u0442\u0430.<\/p>\n<p>\u0414\u043b\u044f \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u044f Python \u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u0432 \u0441\u0442\u0440\u043e\u043a\u0443 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442\u0441\u044f \u0442\u0440\u0438 API \u043c\u0435\u0442\u043e\u0434\u0430:<\/p>\n<ul>\n<li>\n<p><strong>PyObject_Repr<\/strong>,<\/p>\n<\/li>\n<li>\n<p><strong>PyUnicode_AsEncodedString<\/strong>,<\/p>\n<\/li>\n<li>\n<p><strong>PyBytes_AsString<\/strong>.<\/p>\n<\/li>\n<\/ul>\n<p>\u041f\u0435\u0440\u0432\u044b\u0439 \u043c\u0435\u0442\u043e\u0434 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u0443\u0435\u0442 \u043e\u0431\u044a\u0435\u043a\u0442 Python \u0432\u043e \u0432\u043d\u0443\u0442\u0440\u0435\u043d\u043d\u0435\u0435 \u0441\u0442\u0440\u043e\u043a\u043e\u0432\u043e\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435 Python, \u0432\u044b\u0434\u0430\u0432\u0430\u044f \u043d\u0430 \u0432\u044b\u0445\u043e\u0434 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u043d\u044b\u0439 \u043e\u0431\u044a\u0435\u043a\u0442 Python. \u042d\u0442\u043e \u0430\u043d\u0430\u043b\u043e\u0433 \u043c\u0435\u0442\u043e\u0434\u0430 <em>repr(.)<\/em> Python.<\/p>\n<p>\u0412\u0442\u043e\u0440\u043e\u0439 \u043c\u0435\u0442\u043e\u0434 \u0444\u043e\u0440\u043c\u0438\u0440\u0443\u0435\u0442 \u0431\u0430\u0439\u0442\u043e\u0432\u043e\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0441\u0442\u0440\u043e\u043a\u0438, \u043f\u0440\u0438\u0433\u043e\u0434\u043d\u043e\u0435 \u0434\u043b\u044f \u043f\u0435\u0440\u0435\u0434\u0430\u0447\u0438 \u0432 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043a\u0430\u043d\u0430\u043b \u0441\u0432\u044f\u0437\u0438. \u041d\u0430 \u0432\u044b\u0445\u043e\u0434\u0435 \u0438\u043c\u0435\u0435\u043c \u043e\u0431\u044a\u0435\u043a\u0442 Python.<\/p>\n<p>\u041d\u0430\u043a\u043e\u043d\u0435\u0446, \u0442\u0440\u0435\u0442\u0438\u0439 \u043c\u0435\u0442\u043e\u0434 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043f\u043e \u0433\u043e\u0442\u043e\u0432\u043e\u043c\u0443 \u043e\u0431\u044a\u0435\u043a\u0442\u0443 Python \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c \u043d\u0430 \u0431\u0430\u0439\u0442\u044b \u0438\u0441\u043a\u043e\u043c\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0438. \u0412 \u043d\u0430\u0448\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0430\u043d\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u044e\u0442\u0441\u044f \u0447\u0438\u0441\u043b\u0430, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0431\u0430\u0439\u0442\u044b \u0441\u043e\u0432\u043f\u0430\u0434\u0430\u044e\u0442 \u0441 \u0441\u0438\u043c\u0432\u043e\u043b\u0430\u043c\u0438: \u0446\u0438\u0444\u0440\u0430\u043c\u0438 0&#8230;9, \u0437\u043d\u0430\u043a\u043e\u043c \u043c\u0438\u043d\u0443\u0441, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u044d\u0442\u0438 \u0431\u0430\u0439\u0442\u044b \u043c\u043e\u0436\u043d\u043e \u043d\u0430\u043f\u0440\u044f\u043c\u0443\u044e \u0441\u0440\u0430\u0432\u043d\u0438\u0432\u0430\u0442\u044c \u0441 \u0431\u0430\u0439\u0442\u0430\u043c\u0438 \u0441\u0442\u0440\u043e\u043a\u043e\u0432\u043e\u0433\u043e \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0434\u0440\u0443\u0433\u0438\u0445 \u0447\u0438\u0441\u0435\u043b &#8212; \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u043e\u0432 \u0441\u0447\u0435\u0442\u0430 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0430 \u043d\u0430 \u0421++.<\/p>\n<p>\u041d\u0430\u0431\u043e\u0440 \u043c\u0435\u0442\u043e\u0434\u043e\u0432 \u0434\u043b\u044f \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d \u043d\u0438\u0436\u0435.<\/p>\n<details class=\"spoiler\">\n<summary>\u041c\u0435\u0442\u043e\u0434\u044b \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0430 \u0434\u0435\u043b\u0435\u043d\u0438\u044f 128-\u0431\u0438\u0442\u043d\u044b\u0445 \u0447\u0438\u0441\u0435\u043b<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"cpp\">#include &lt;algorithm> #include &lt;cassert> #include &lt;cmath> #include &lt;cstdint> #include &lt;iostream> #include &lt;random> #include &lt;string> #include &lt;string.h> #include &lt;python3.10\/Python.h>  using u64 = uint64_t; using ULOW = u64; \/\/ \u0422\u0438\u043f \u043f\u043e\u043b\u043e\u0432\u0438\u043d\u043e\u043a: \u0441\u0442\u0430\u0440\u0448\u0435\u0439 \u0438 \u043c\u043b\u0430\u0434\u0448\u0435\u0439 \u0447\u0430\u0441\u0442\u0435\u0439 \u0441\u043e\u0441\u0442\u0430\u0432\u043d\u043e\u0433\u043e \u0447\u0438\u0441\u043b\u0430.  static_assert(CHAR_BIT == 8);  struct Quadrupole { \/\/ \u0421\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430 \u0434\u043b\u044f \u0437\u0430\u0434\u0430\u043d\u0438\u044f \u0434\u0440\u043e\u0431\u0438 (A*M + B) \/ (C*M + D).                     \/\/ M - \u043c\u043d\u043e\u0436\u0438\u0442\u0435\u043b\u044c \u0441\u0438\u0441\u0442\u0435\u043c\u044b \u0441\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f, 2^W, W - \u0431\u0438\u0442\u043e\u0432\u0430\u044f \u0448\u0438\u0440\u0438\u043d\u0430 \u043f\u043e\u043b\u043e\u0432\u0438\u043d\u043e\u043a.     ULOW A;     ULOW B;     ULOW C;     ULOW D; };  struct Signess { \/\/ \u0421\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430 \u0434\u043b\u044f \u0437\u0430\u0434\u0430\u043d\u0438\u044f \u0437\u043d\u0430\u043a\u043e\u0432 \u0434\u0432\u0443\u0445 \u0447\u0438\u0441\u0435\u043b.     bool s1;     bool s2; };  static auto const seed = std::random_device{}();  \/***  * \u0413\u0435\u043d\u0435\u0440\u0430\u0442\u043e\u0440 \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u044b\u0445 \u0447\u0438\u0441\u0435\u043b.  *\/ auto roll_ulow = [urbg = std::mt19937{seed},                 distr = std::uniform_int_distribution&lt;ULOW>{}]() mutable -> ULOW {     return distr(urbg); };  auto roll_uint = [urbg = std::mt19937{seed},                 distr = std::uniform_int_distribution&lt;uint>{}]() mutable -> uint {     return distr(urbg); };  auto roll_bool = [urbg = std::mt19937{seed},                 distr = std::uniform_int_distribution&lt;uint>{}]() mutable -> bool {     return distr(urbg) % 2; };  \/**  * \u0422\u0435\u0441\u0442 \u0434\u0435\u043b\u0435\u043d\u0438\u044f \u0434\u0432\u0443\u0445 128-\u0431\u0438\u0442\u043d\u044b\u0445 \u0447\u0438\u0441\u0435\u043b.  * @param z1 \u0414\u0435\u043b\u0438\u043c\u043e\u0435.  * @param z2 \u0414\u0435\u043b\u0438\u0442\u0435\u043b\u044c.  * @return \u0423\u0441\u043f\u0435\u0445\/\u043d\u0435\u0443\u0434\u0430\u0447\u0430. *\/ bool test_div(U128 z1, U128 z2, PythonCaller&amp; caller) {     const U128 z3 = z1 \/ z2;     PyObject* quotient = caller.Divide(z1, z2);     return caller.Compare(quotient, z3.value().c_str()); }  \/**  * \u041f\u043e\u043b\u0443\u0441\u043b\u0443\u0447\u0430\u0439\u043d\u044b\u0439 \u0442\u0435\u0441\u0442 \u0434\u0435\u043b\u0435\u043d\u0438\u044f 128-\u0431\u0438\u0442\u043d\u044b\u0445 \u0447\u0438\u0441\u0435\u043b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u043d\u044b\u0439 \u043d\u0430\u0431\u043e\u0440 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u0432\u0431\u043b\u0438\u0437\u0438 \u0443\u0433\u043b\u043e\u0432\u044b\u0445 \u0438 \u0433\u0440\u0430\u043d\u0438\u0447\u043d\u044b\u0445.  * @param N \u041a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0432\u043d\u0435\u0448\u043d\u0438\u0445 \u0438\u0442\u0435\u0440\u0430\u0446\u0438\u0439. *\/ void test_division_semi_randomly(long long N) {     if (N &lt; 1) {         std::cout &lt;&lt; \"Skipped!\\n\";         return;     }     PythonCaller caller;     const std::vector&lt;u64> choice {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10,                                      65535, 65534, 65533, 65532, 65531, 65530,                                      16384, 16383, 16382, 16385, 16386, 16387, 16388,                                      -1ull, -2ull, -3ull, -4ull, -5ull, -6ull, -7ull};     auto make_test = [&amp;caller](const Quadrupole q, const Signess s) -> bool {         return test_div(U128{.mHigh = q.A, .mLow = q.B, .mSign = s.s1},                         U128{.mHigh = q.C, .mLow = q.D, .mSign = s.s2},                         caller);     };     auto get_quadrupole = [&amp;choice]() -> Quadrupole {         auto idx1 = roll_uint() % choice.size();         auto idx2 = roll_uint() % choice.size();         auto idx3 = roll_uint() % choice.size();         auto idx4 = roll_uint() % choice.size();         Quadrupole q {choice[idx1], choice[idx2], choice[idx3], choice[idx4]};         return q;     };     long long counter = 0;     long long external_iterations = 0;     bool is_ok = true;     while (external_iterations &lt; N) {         ++counter;         const Quadrupole q = get_quadrupole();         const Signess s{roll_bool(), roll_bool()};         if (q.C == 0 &amp;&amp; q.D == 0) {             continue;         }         is_ok &amp;= make_test(q, s);         assert(is_ok);         if (counter % (1ll &lt;&lt; 20) == 0) {             external_iterations++;             std::cout &lt;&lt; \"... iterations: \" &lt;&lt; counter &lt;&lt; \". External: \" &lt;&lt;                  external_iterations &lt;&lt; \" from \" &lt;&lt; N &lt;&lt; '\\n';         }     } }  \/**  * \u0421\u043b\u0443\u0447\u0430\u0439\u043d\u044b\u0439 \u0442\u0435\u0441\u0442 \u0434\u0435\u043b\u0435\u043d\u0438\u044f 128-\u0431\u0438\u0442\u043d\u044b\u0445 \u0447\u0438\u0441\u0435\u043b.  * @param N \u041a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0432\u043d\u0435\u0448\u043d\u0438\u0445 \u0438\u0442\u0435\u0440\u0430\u0446\u0438\u0439. *\/ void test_division_randomly(long long N) {     if (N &lt; 1) {         std::cout &lt;&lt; \"Skipped!\\n\";         return;     }     PythonCaller caller;     auto make_test = [&amp;caller](const Quadrupole q, const Signess s) -> bool {         return test_div(U128{.mHigh = q.A, .mLow = q.B, .mSign = s.s1},                         U128{.mHigh = q.C, .mLow = q.D, .mSign = s.s2},                         caller);     };     auto get_quadrupole = []() -> Quadrupole {         Quadrupole q {roll_ulow(), roll_ulow(), roll_ulow(), roll_ulow()};         return q;     };     long long counter = 0;     long long external_iterations = 0;     bool is_ok = true;  <\/code><\/pre>\n<\/div>\n<\/details>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-375918","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/375918","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=375918"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/375918\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=375918"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=375918"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=375918"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}