Blame view

12.py 546 Bytes
Imanol-Mikel Barba Sabariego authored
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#!/usr/bin/python

import sys;
import math;

def getNumFactors(num):

	count = 0;
	for x in range (1,int(math.ceil(num/2))+1):
		if((num % x) == 0):
			count += 1;

	return count+1;

def calculateTriangleNumber(pos):

	sum = 0;
	for i in range (1,pos+1):
		sum += i;

	return sum;

def getTriangleNumber(numFactors):
	num = 2;
	while(True):
		if(getNumFactors(calculateTriangleNumber(num)) > numFactors):
			return calculateTriangleNumber(num);
		num += 1;

numFactors = int(sys.argv[1]);
print "Result is: " + str(getTriangleNumber(numFactors));