def gauss_to_string(l, m, numeric=False): """Return string representation of the generalized gaussian:: _____ 2 m / 1 l! l+3/2 -a r l m g (x,y,z) = / ----- --------- (4 a) e r Y (x,y,z) l \/ 4 pi (2l + 1)! l numeric=True/False indicates whether the normalization constant should be written as a number or an algebraic expression. """ norm, xyzs = Y_collect(l, m) ng = Q(2**(2*l+3) * factorial(l), 2 * factorial(2 * l + 1)) norm.multiply(ng) string = to_string(l, xyzs) string = (' * ' + string) * (string != '1') if numeric: snorm = repr(eval(repr(norm.norm))) else: snorm = repr(norm.norm) string = 'sqrt(a**%s*%s)/pi'%(2*l+3, snorm) + string string += ' * exp(-a*r2)' return string
def gauss_to_string(l, m, numeric=False): """Return string representation of the generalized gaussian:: _____ 2 m / 1 l! l+3/2 -a r l m g (x,y,z) = / ----- --------- (4 a) e r Y (x,y,z) l \/ 4 pi (2l + 1)! l numeric=True/False indicates whether the normalization constant should be written as a number or an algebraic expression. """ norm, xyzs = Y_collect(l, m) ng = Q(2**(2 * l + 3) * factorial(l), 2 * factorial(2 * l + 1)) norm.multiply(ng) string = to_string(l, xyzs) string = (' * ' + string) * (string != '1') if numeric: snorm = repr(eval(repr(norm.norm))) else: snorm = repr(norm.norm) string = 'sqrt(a**%s*%s)/pi' % (2 * l + 3, snorm) + string string += ' * exp(-a*r2)' return string
def get(n): # n! / ((n/2 !) * (n/2 !)) = (n * (n-1) * (n-2) * (n-3) .... ((n/2)+1)) / ((n/2)!) # ------------------ t --------------------- t = 1 for i in range(n, int(n / 2), -1): t *= i return int(t / factorial(int(n / 2)))
def __init__(self, l, m): m = abs(m) if m == 0: self.norm = Q(2 * l + 1, 4) else: self.norm = Q((2 * l + 1) * factorial(l - m), 2 * factorial(l + m))
def perm(l, n): if len(l) <= 1: return l fct = factorial(len(l) - 1) q, r = n / fct, n % fct return [l[q]] + perm(l[:q] + l[q + 1 :], r)
from tools import factorial print sum([ int(n) for n in str(factorial(100))])
import tools limit = tools.factorial(9)*7 i = 10 results = [] while i<=limit: s = str(i) if i < tools.factorial(9) and ('9' in s): i += 1 continue if i < tools.factorial(8) and ('8' in s): i += 1 continue if i < tools.factorial(7) and ('7' in s): i += 1 continue summa = 0 for x in [int(c) for c in s]: summa += tools.factorial(x) if summa > i: break if summa == i: results.append(i) print sum(results) i += 1 print sum(results)
import tools results = 0 for n in range(23, 101): nf = tools.factorial(n) if nf <= 1000000: continue for r in range(2, n + 1): rf = tools.factorial(r) if nf / rf <= 1000000: continue if nf / rf / tools.factorial(n - r) > 1000000: results += 1 print results
from tools import factorial #Precalculate factorials of 0..9 FACTORIAL = {} for i in range(0, 10): FACTORIAL[str(i)] = factorial(i) UPPER_BOUND = 7 * FACTORIAL['9'] + 1 s = 0 for i in xrange(10, UPPER_BOUND, 1): if sum(FACTORIAL[c] for c in str(i)) == i: s += i print s
def factsum(x): s = 0 while x: s += tools.factorial(x%10) x /= 10 return s
def pe020(): """# Find the digit-sum of '100!'""" from tools import factorial, digitSum return digitSum(factorial(100))