Created
August 20, 2018 19:03
-
-
Save chermehdi/7d5b5397a019b842c8ea73f1328e63b9 to your computer and use it in GitHub Desktop.
divisors
This file contains hidden or 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
def generate_primes(n): | |
seive = [True] * n | |
pr = [] | |
for i in range(2, n): | |
if seive[i]: | |
j = 2 * i | |
while j < n: | |
seive[j] = False | |
j += i | |
pr.append(i) | |
return pr | |
primes = generate_primes(1000) | |
fact = [[0 for x in range(1000)] for y in range(1000)] | |
def power_in_factorial(p, n): | |
"""Return the exponent of the prime p in the factorization of n!""" | |
result = 0 | |
while True: | |
n //= p | |
if not n: | |
break | |
result += n | |
return result | |
def count_factorial(n): | |
dic = {} | |
for prime in primes: | |
if prime > n: break | |
dic[prime] = power_in_factorial(prime, n) | |
return dic | |
n, k = 6, 3 | |
def diff(a, b): | |
for key in b: | |
a[key] -= b[key] | |
return a | |
def get(dic): | |
val = 1 | |
for key in dic: | |
val *= (dic[key] + 1) | |
return val | |
def choose(n): | |
cc = [[0 for x in range(n + 1)] for y in range(n + 1)] | |
for i in range(1, n): | |
for j in range(1, i + 1): | |
a, b, c, = count_factorial(i), count_factorial(j), count_factorial(i - j) | |
a = diff(a, b) | |
a = diff(a, c) | |
ans = get(a) | |
cc[i][j] = ans | |
return cc | |
c = choose(435) | |
for i in range(434): | |
for j in range(i + 1): | |
print("{} ".format(c[i][j]), end = "") | |
print() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment