def isprime( n ):
    """ check if n is a prime, adapted from:
       http://www.daniweb.com/software-development/python/code/216880/
              check-if-a-number-is-a-prime-number-python
    """
    if (n <= 0 or n % 2 == 0):
        return False
    if (n < 3):
        return True
    for i in range(3, int(n**0.5)+1, 2):
        if (n % i == 0):
            return False
    return True