diff options
| author | Andrew Guschin <guschin.drew@gmail.com> | 2023-12-19 01:38:52 +0400 |
|---|---|---|
| committer | Andrew Guschin <guschin.drew@gmail.com> | 2023-12-19 01:38:52 +0400 |
| commit | 3cbc233c0af1ca1726a1c34c37677bf0b0eb8d60 (patch) | |
| tree | 06f545b627b51a4f6bdecaa68f913e5169952297 | |
| parent | 6c2e055e0497b0f5b3a396fc7e058a563ac9735b (diff) | |
задание 2
| -rw-r--r-- | t4mk.ipynb | 208 |
1 files changed, 208 insertions, 0 deletions
@@ -218,6 +218,214 @@ ] }, { + "cell_type": "code", + "execution_count": 187, + "metadata": {}, + "outputs": [ + { + "data": { + "text/latex": [ + "$\\displaystyle \\text{Свойство 1:}$" + ], + "text/plain": [ + "<IPython.core.display.Math object>" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "$\\displaystyle a \\equiv b \\pmod{p} \\implies \\left(\\frac{a}{p}\\right) = \\left(\\frac{b}{p}\\right)$" + ], + "text/plain": [ + "<IPython.core.display.Math object>" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "$\\displaystyle \\text{Свойство 6:}$" + ], + "text/plain": [ + "<IPython.core.display.Math object>" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "$\\displaystyle \\left(\\frac{2}{p}\\right) = \\begin{cases}\n", + " 1, &\\text{если } p \\equiv \\pm 1 \\pmod{8} \\\\\n", + "-1, &\\text{если } p \\equiv \\pm 3 \\pmod{8}\n", + "\\end{cases}$" + ], + "text/plain": [ + "<IPython.core.display.Math object>" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "$\\displaystyle \\text{Свойство 7 (Квадратичный закон взаимности Гаусса):}$" + ], + "text/plain": [ + "<IPython.core.display.Math object>" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "$\\displaystyle \\left(\\frac{p}{q}\\right) = \\left(\\frac{q}{p}\\right) \\cdot (-1)^{\\frac{p - 1}{2} \\cdot \\frac{q - 1}{2}}$" + ], + "text/plain": [ + "<IPython.core.display.Math object>" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "$\\displaystyle \\text{Решение:}$" + ], + "text/plain": [ + "<IPython.core.display.Math object>" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "$\\displaystyle \\left(\\frac{1016}{2945}\\right) = $" + ], + "text/plain": [ + "<IPython.core.display.Math object>" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "$\\displaystyle = (1) \\cdot \\left(\\frac{1016}{2945}\\right) = (1) \\cdot \\left(\\frac{2^3}{2945}\\right) \\cdot \\left(\\frac{127}{2945}\\right) = \\text{[по св. 6]} = (1) \\cdot \\left(\\frac{127}{2945}\\right) =\\text{[по св. 7 Гаусса]} = (1) \\cdot \\left(\\frac{2945}{127}\\right) \\cdot (-1)^{\\frac{2945 - 1}{2} \\cdot \\frac{127 - 1}{2}} =(1) \\cdot \\left(\\frac{2945}{127}\\right) = \\text{[по св. 1]} = (1) \\cdot \\left(\\frac{24}{127}\\right) = $" + ], + "text/plain": [ + "<IPython.core.display.Math object>" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "$\\displaystyle = (1) \\cdot \\left(\\frac{24}{127}\\right) = (1) \\cdot \\left(\\frac{2^3}{127}\\right) \\cdot \\left(\\frac{3}{127}\\right) = \\text{[по св. 6]} = (1) \\cdot \\left(\\frac{3}{127}\\right) =\\text{[по св. 7 Гаусса]} = (1) \\cdot \\left(\\frac{127}{3}\\right) \\cdot (-1)^{\\frac{127 - 1}{2} \\cdot \\frac{3 - 1}{2}} =(-1) \\cdot \\left(\\frac{127}{3}\\right) = \\text{[по св. 1]} = (-1) \\cdot \\left(\\frac{1}{3}\\right) = $" + ], + "text/plain": [ + "<IPython.core.display.Math object>" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "$\\displaystyle = (-1) \\cdot \\left(\\frac{1}{3}\\right) = \\text{[по св. 7 Гаусса]} = (-1) \\cdot \\left(\\frac{3}{1}\\right) \\cdot (-1)^{\\frac{3 - 1}{2} \\cdot \\frac{1 - 1}{2}} =(-1) \\cdot \\left(\\frac{3}{1}\\right) = \\text{[по св. 1]} = (-1) \\cdot \\left(\\frac{0}{1}\\right) = $" + ], + "text/plain": [ + "<IPython.core.display.Math object>" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "$\\displaystyle = -1$" + ], + "text/plain": [ + "<IPython.core.display.Math object>" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "a, n = 1016, 2945\n", + "\n", + "def jacobi(a, n):\n", + " ans = 1\n", + " if a == 1:\n", + " return ans\n", + " while a != 0:\n", + " ltx = []\n", + " ltx.append(fr'''= ({ans}) \\cdot \\left(\\frac{{{a}}}{{{n}}}\\right) = ''')\n", + "\n", + " count = 0\n", + " while a % 2 == 0:\n", + " a //= 2\n", + " count += 1\n", + " if n % 8 in {3, 5}:\n", + " ans = -ans\n", + "\n", + " if count != 0:\n", + " ltx.append(fr\"({ans}) \\cdot \\left(\\frac{{2^{count}}}{{{n}}}\\right) \\cdot \\left(\\frac{{{a}}}{{{n}}}\\right) = \")\n", + " ltx.append(fr\"\\text{{[по св. 6]}} = ({ans}) \\cdot \\left(\\frac{{{a}}}{{{n}}}\\right) =\")\n", + "\n", + " a, n = n, a\n", + " ltx.append(fr\"\\text{{[по св. 7 Гаусса]}} = ({ans}) \\cdot \\left(\\frac{{{a}}}{{{n}}}\\right) \\cdot (-1)^{{\\frac{{{a} - 1}}{{2}} \\cdot \\frac{{{n} - 1}}{{2}}}} =\")\n", + " if a % 4 == n % 4 == 3:\n", + " ans = -ans\n", + " ltx.append(fr\"({ans}) \\cdot \\left(\\frac{{{a}}}{{{n}}}\\right) = \")\n", + " a %= n\n", + " ltx.append(fr\"\\text{{[по св. 1]}} = ({ans}) \\cdot \\left(\\frac{{{a}}}{{{n}}}\\right) = \")\n", + "\n", + " display(Math(''.join(ltx)))\n", + "\n", + " if n == 1:\n", + " return ans\n", + " else:\n", + " return 0\n", + "\n", + "display(Math(r'\\text{Свойство 1:}'))\n", + "display(Math(r'a \\equiv b \\pmod{p} \\implies \\left(\\frac{a}{p}\\right) = \\left(\\frac{b}{p}\\right)'))\n", + "\n", + "display(Math(r'\\text{Свойство 6:}'))\n", + "display(Math(r'''\\left(\\frac{2}{p}\\right) = \\begin{cases}\n", + " 1, &\\text{если } p \\equiv \\pm 1 \\pmod{8} \\\\\n", + "-1, &\\text{если } p \\equiv \\pm 3 \\pmod{8}\n", + "\\end{cases}'''))\n", + "\n", + "display(Math(r'\\text{Свойство 7 (Квадратичный закон взаимности Гаусса):}'))\n", + "display(Math(r'\\left(\\frac{p}{q}\\right) = \\left(\\frac{q}{p}\\right) \\cdot (-1)^{\\frac{p - 1}{2} \\cdot \\frac{q - 1}{2}}'))\n", + "\n", + "display(Math(r'\\text{Решение:}'))\n", + "display(Math(fr\"\\left(\\frac{{{a}}}{{{n}}}\\right) = \"))\n", + "res = jacobi(a, n)\n", + "display(Math(f\" = {res}\"))" + ] + }, + { "cell_type": "markdown", "metadata": {}, "source": [ |