Created
December 30, 2011 09:53
-
-
Save j605/1539065 to your computer and use it in GitHub Desktop.
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 get_triangle_no(): | |
num = [1, 3] | |
i = 2 | |
while 1 > 0: | |
num.append(num[i - 1] + i + 1) | |
if num[i] > 500000000000000000000 and factors(num[i]) > 500: | |
return num[i] | |
i = i + 1 | |
def mark(numbers, p, N): | |
if p*p <= N: | |
i = 2 * p | |
while i <= N and i >= p*p: | |
numbers[i] = False | |
i = i + p | |
return numbers | |
def get_numbers(N): | |
i = 2 | |
numbers = {} | |
while i <= N: | |
numbers[i] = True | |
i = i + 1 | |
primes = [2] | |
p = 2 | |
while p <= N: | |
numbers = mark(numbers, p, N) | |
j = p + 1 | |
while j < N: | |
if numbers[j] is True: | |
p = j | |
primes.append(p) | |
break | |
j = j + 1 | |
if j == N: | |
break | |
return primes | |
primes = get_numbers(50000000000000000000000) | |
def factors(num): | |
fac = 1 | |
sum = 0 | |
j = 0 | |
while primes[j] < num/2: | |
while temp_num % primes[j]: | |
temp_num /= primes[j] | |
sum += 1 | |
j += 1 | |
fac *= (sum + 1) | |
sum = 0 | |
return sum | |
print ge_triangle_no() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment