Professional Documents
Culture Documents
#
#
#
#
Version 1.0
2015-07-09
Author: Catherine Hsu
This code requires PARI to be in the same folder as codeforbiquadratic.py.
#*****************************************************************************
#
Copyright (C) 2015 Catherine Hsu <cathyh@uoregon.edu>
#
# Distributed under the terms of the GNU General Public License (GPL)
#
#
This code is distributed in the hope that it will be useful,
#
but WITHOUT ANY WARRANTY; without even the implied warranty of
#
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
#
General Public License for more details.
#
# The full text of the GPL is available at:
#
#
http://www.gnu.org/licenses/
#*****************************************************************************
from subprocess import PIPE, Popen
def prime_factors(n):
i = 2
factors = []
while i * i <= n:
if n % i:
i += 1
else:
n //= i
factors.append(i)
if n > 1:
factors.append(n)
return factors
def is_prime(x):
if x<2:
return False
elif x == 2:
return True
else:
for n in range(2, x):
if x%n==0:
return False
return True
def do_pari(command):
proc = Popen(['gp.exe'],stdin=PIPE,stdout=PIPE)
pcomm = bytes(command,'UTF-8')
proc.stdin.write(pcomm)
out = str(proc.communicate()[0])
out=out[675:]
out = out[:-17]
proc.terminate()
return out