# L-16 MCS 507 Wed 27 Sep 2023 : factorial50_sympy.py
# """
# This script is the first step to test the prime factorization
# of 50! with Sage and SymPy.
#  
# The source for this test are problems C1 and C2 from
# Chapter 3 by Michael J. Wester: "A Critique of the
# Mathematical Abilities of CA Systems", pages 25-60.
# In "Computer Algebra Systems.  A Practical Guide"
# edited by Michael J. Wester, Wiley 1999.
# 
# If saved as 'factorial50_sympy.py', execute this script at
# the command line as 'python factorial50_sympy.py'.
#  
# The first two number problems C1 and C2 are
# (1) to compute 50! the factorial of 50; and
# (2) to factor 50! in irreducible factors.
# We can test for the number of decimal places in 50!
# and the number of distinct prime factors of 50!.
# 
# Instead of a documentation string, all documentation is
# formatted via the comment line symbols.
# """
import sympy as sp
N = sp.factorial(50)
print('50! =', N)
print('50! has', len(str(N)), 'decimal places')
F = sp.factorint(N)
K = list(F.keys())
K.sort()
L = [str(x)+'^'+str(F[x]) for x in K]
S = ' '.join(L)
print('50! =', S)
print('50! has', len(F.keys()), 'prime factors')
