def isSumOfDigitFactorial(n): sum = 0 for digitChr in str(n): digit = int(digitChr) sum += factorial(digit) if sum > n: return False return sum == n
from zMath import nthLexiPerm from zMath import factorial def hasWeirdProperty(n): #10 digit number s = str(n) if s[0] == '0': return False return int(s[1:4]) % 2 == 0 and int(s[2:5]) % 3 == 0 and int(s[3:6]) % 5 == 0 and int(s[4:7]) % 7 == 0 and int(s[5:8]) % 11 == 0 and int(s[6:9]) % 13 == 0 and int(s[7:10]) % 17 == 0 sum = 0 sequence = range(0, 10) #should probably write a permutation generator instead of using this function for permutationIndex in range(0, factorial(10)): permutation = nthLexiPerm(sequence, permutationIndex) if hasWeirdProperty(permutation): sum += int(permutation) print sum
from zMath import nthLexiPerm from zMath import isPrimeSimple from zMath import factorial import sys for numDigits in range(9, 0, -1): sequence = range(1, numDigits+1) sequence.reverse() #should probably write a function to generate all permutations for permutationIndex in range(0, factorial(numDigits)): permutationStr = nthLexiPerm(sequence, permutationIndex) #print str(permutationIndex) + ": "+str(permutationStr) permutation = int(permutationStr) if isPrimeSimple(permutation): print permutation sys.exit(0)
from zMath import factorial print (factorial(40) / (factorial(20) * factorial(20)))
from zMath import factorial maxExp = 1 while True: if factorial(9)*maxExp < 10**maxExp: break else: maxExp += 1 def isSumOfDigitFactorial(n): sum = 0 for digitChr in str(n): digit = int(digitChr) sum += factorial(digit) if sum > n: return False return sum == n sum = 0 for i in range(10, 10**(maxExp-1)): if isSumOfDigitFactorial(i): sum += i print sum
from zMath import factorial numStr = str(factorial(100)) sum = 0 for c in numStr: sum += int(c) print sum