old_12.py
546 Bytes
#!/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));