Created
August 9, 2021 09:11
-
-
Save foxqstm/e5c5950f663870771ba0cc3393eda1f0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"cells": [ | |
{ | |
"cell_type": "code", | |
"execution_count": 1, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"['3/2']\n" | |
] | |
} | |
], | |
"source": [ | |
"import sympy\n", | |
"\n", | |
"a=[2,-3,6,-11,1,3] #constant term is a[-1]\n", | |
"\n", | |
"pnl=sympy.ntheory.divisors(a[-1])\n", | |
"ml=sympy.ntheory.divisors(a[0])\n", | |
"\n", | |
"nl=[]\n", | |
"for div in pnl:\n", | |
" nl.append(div)\n", | |
" nl.append(-div)\n", | |
"\n", | |
"deg=len(a)-1\n", | |
"f=0\n", | |
"ans=[]\n", | |
"for n in nl:\n", | |
" for m in ml:\n", | |
" nd=n**deg\n", | |
" md=1\n", | |
" for c in a:\n", | |
" f+=nd*md*c\n", | |
" nd/=n\n", | |
" md*=m\n", | |
" if f==0:\n", | |
" ans.append((str(n)+'/'+str(m)))\n", | |
" f=0\n", | |
" \n", | |
"print(ans)" | |
] | |
} | |
], | |
"metadata": { | |
"kernelspec": { | |
"display_name": "Python 3", | |
"language": "python", | |
"name": "python3" | |
}, | |
"language_info": { | |
"codemirror_mode": { | |
"name": "ipython", | |
"version": 3 | |
}, | |
"file_extension": ".py", | |
"mimetype": "text/x-python", | |
"name": "python", | |
"nbconvert_exporter": "python", | |
"pygments_lexer": "ipython3", | |
"version": "3.6.5" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 2 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment