Project Euler #44: Pentagon numbers

  • + 0 comments

    from math import sqrt :

    def ispentagonal(a) :

    if a <= 0 :
    
        return False
    
    delt = 1 + 24 * a
    x1 = (1 - sqrt(delt)) / 6
    x2 = (1 + sqrt(delt)) / 6
    
    if x1 > 0 and x1.is_integer():
        return True
    if x2 > 0 and x2.is_integer():
        return True