Problem 179

completed January 21, 2012

Comments

I approached this as I do finding primes. All I needed to test was up to the square root of the number. For every factor found, there’s a matching one that it needs to be multiplied by to get the original number.

The script took a little longer to run than I would have liked, but it worked none the less.

Code

def divnum(n):
	if n == 1 or n**.5%1 == 0:
		count = 1
	else:
		count = 2
	for i in range(2, int(n**.5)+1):
		if n%i == 0:
			count += 2
	return count

pre = 10
count = 0

for n in range(1, 10**7):
	if n%10**5 == 0: print n
	div = divnum(n)
	if div == pre:
		count += 1
	pre = div

print count