.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "api/gallery/number_theory/crt/plot_01_sunzi_problem.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr_api_gallery_number_theory_crt_plot_01_sunzi_problem.py: Sunzi's classic "remainder problem" ========================================= The 3rd-5th-century Chinese text *Sunzi Suanjing* poses: "There are certain things whose number is unknown. Repeatedly divided by 3, the remainder is 2; by 5 the remainder is 3; by 7 the remainder is 2. What is the number?" -- the original problem the Chinese Remainder Theorem is named for. .. GENERATED FROM PYTHON SOURCE LINES 13-15 .. code-block:: Python from mathematicskit.number_theory import chinese_remainder_theorem .. GENERATED FROM PYTHON SOURCE LINES 16-18 Solve Sunzi's problem ----------------------------------------------------- .. GENERATED FROM PYTHON SOURCE LINES 18-24 .. code-block:: Python result = chinese_remainder_theorem(remainders=[2, 3, 2], moduli=[3, 5, 7]) print(f"x = {result.residue} (mod {result.modulus})") for r, m in zip([2, 3, 2], [3, 5, 7]): print(f" {result.residue} mod {m} = {result.residue % m} (expected {r})") .. rst-class:: sphx-glr-script-out .. code-block:: none x = 23 (mod 105) 23 mod 3 = 2 (expected 2) 23 mod 5 = 3 (expected 3) 23 mod 7 = 2 (expected 2) .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.000 seconds) .. _sphx_glr_download_api_gallery_number_theory_crt_plot_01_sunzi_problem.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_01_sunzi_problem.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_01_sunzi_problem.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_01_sunzi_problem.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_