Not a member of Pastebin yet?
                        Sign Up,
                        it unlocks many cool features!                    
                - def isPrime(n):
 - '''
 - Returns True if the given number is a prime.
 - '''
 - for x in xrange(2, n):
 - if n % x == 0:
 - return False
 - return True
 - def getPrimes(n):
 - '''
 - Returns all primes until <n> as a generator.
 - '''
 - return (x for x in xrange(2, n+1) if isPrime(x))
 - def getEdges(n):
 - '''
 - Returns the count of all edges within a Hasse-diagram until <n>.
 - '''
 - count = 0
 - primes = tuple(getPrimes(n))
 - for x in xrange(1, n+1):
 - for divisor in primes:
 - if divisor > x:
 - break
 - if x % divisor == 0:
 - count += 1
 - return count
 - print getEdges(5000)
 
Advertisement
 
                    Add Comment                
                
                        Please, Sign In to add comment