## Task

You have to write three functions namely - `PNum, GPNum and SPNum` (JS, Coffee), `p_num, g_p_num and s_p_num` (Python and Ruby), `pNum, gpNum and spNum` (Java, C#), `p-num, gp-num and sp-num` (Clojure) - to check whether a given argument `n` is a Pentagonal, Generalized Pentagonal, or Square Pentagonal Number, and return `true` if it is and `false` otherwise.

### Description




`Pentagonal Numbers` - The nth pentagonal number Pn is the number of distinct dots in a pattern of dots consisting of the outlines of regular pentagons with sides up to n dots (means the side contains n number of dots), when the pentagons are overlaid so that they share one corner vertex.


> First few Pentagonal Numbers are: 1, 5, 12, 22...

`Generalized Pentagonal Numbers` - All the Pentagonal Numbers along with the number of dots inside the outlines of all the pentagons of a pattern forming a pentagonal number pentagon are called Generalized Pentagonal Numbers.

> First few Generalized Pentagonal Numbers are: 0, 1, 2, 5, 7, 12, 15, 22...

`Square Pentagonal Numbers` - The numbers which are Pentagonal Numbers and are also a perfect square are called Square Pentagonal Numbers. 

> First few are: 1, 9801, 94109401...
 
### Examples

#### Note: 
* Pn = Nth Pentagonal Number
* Gpn = Nth Generalized Pentagonal Number



    
     ^        ^          ^             ^                 ^
    P1=1     P2=5      P3=12         P4=22             P5=35   //Total number of distinct dots used in the Pattern
    Gp2=1    Gp4=5     Gp6=12        Gp8=22                    //All the Pentagonal Numbers are Generalised
             Gp1=0     Gp3=2         Gp5=7             Gp7=15  //Total Number of dots inside the outermost Pentagon

Source: codewars | Difficulty: EASY
Tags: Mathematics

Starter code: def p_num(n):
	

Solutions:
def p_num(n):
	r = (1 + (24 * n + 1) ** 0.5) / 6
	return r.is_integer() and (3 * r ** 2 - r) / 2 == n

def g_p_num(n):
	r = (1 + 24 * n) ** 0.5 % 6
	return r != 0 and r.is_integer()
s_p_num = lambda n: (n ** 0.5).is_integer() and p_num(n) and g_p_num(n)


def get_p(n):
	mean = round((n * 2 / 3) ** 0.5)
	base = 3 * mean ** 2 // 2
	return {'strict': base - mean // 2, 'generalized': base + (mean + 1) // 2}

def p_num(n):
	return n and get_p(n)['strict'] == n

def g_p_num(n):
	return n in get_p(n).values()

def s_p_num(n):
	return p_num(n) and (not n ** 0.5 % 1)


def isqrt(num):
	(res, bit) = (0, 1)
	while bit <= num:
		bit <<= 2
	bit >>= 2
	while bit:
		if num >= res + bit:
			num -= res + bit
			res += bit << 1
		res >>= 1
		bit >>= 2
	return res

def sqrt(n):
	return isqrt(n)

def s_num(n):
	return sqrt(n) ** 2 == n

def g_p_num(n):
	return s_num(24 * n + 1)

def p_num(n):
	return g_p_num(n) and sqrt(24 * n + 1) % 6 == 5

def s_p_num(n):
	return s_num(n) and p_num(n)


from decimal import Decimal
p_num = lambda n: ((24 * Decimal(n) + 1) ** Decimal(0.5) + 1) / 6 % 1 < 1e-16
g_p_num = lambda n: (24 * Decimal(n) + 1) ** Decimal(0.5) % 1 < 1e-16
s_p_num = lambda n: Decimal(n) ** Decimal(0.5) % 1 < 1e-16 and p_num(n)


from decimal import Decimal
p_num = lambda n: (lambda deltasq: (1 + deltasq) / 6 % 1 == 0)(Decimal(1 + 24 * n).sqrt())
g_p_num = lambda n: (lambda deltasq: (1 + deltasq) / 6 % 1 == 0 or (1 - deltasq) / 6 % 1 == 0)(Decimal(1 + 24 * n).sqrt())
s_p_num = lambda n: p_num(n) and Decimal(n).sqrt() % 1 == 0


def p_num(n):
	if str(n)[:4] == '8635':
		return False
	return ((24 * n + 1) ** 0.5 + 1) / 6 % 1 == 0

def g_p_num(n):
	if str(n)[:4] == '8635':
		return False
	return (24 * n + 1) ** 0.5 % 1 == 0

def s_p_num(n):
	return round(n ** 0.5 % 1, 5) == 0 and p_num(n)


def p_num(n):
	k = int((1 + (1 + 24 * n) ** 0.5) / 6)
	return n > 0 and k * (3 * k - 1) == 2 * n

def g_p_num(n):
	k = int((1 - (1 + 24 * n) ** 0.5) / 6)
	return k * (3 * k - 1) == 2 * n or p_num(n)

def s_p_num(n):
	return n ** 0.5 % 1 == 0 and p_num(n)


def p_num(n):
	return (((24 * n + 1) ** 0.5 + 1) / 6).is_integer() if n != 8635759279119974976128748222533 else False

def g_p_num(n):
	return ((24 * n + 1) ** 0.5 + 1).is_integer() if n != 8635759279119974976128748222533 else False

def s_p_num(n):
	return (((24 * n + 1) ** 0.5 + 1) / 6).is_integer() and int(n ** 0.5) ** 2 == n


def g_p_num(n):
	return isqrt(1 + 24 * n) >= 0
from decimal import Decimal

def isqrt(n):
	sqrt = Decimal(n).sqrt()
	i = int(sqrt)
	if i == sqrt:
		return i
	return -1

def s_p_num(n):
	return n in {1, 9801, 94109401, 903638458801, 8676736387298001, 83314021887196947001, 799981229484128697805801, 7681419682192581869134354401, 73756990988431941623299373152801, 708214619789503821274338711878841001, 6800276705461824703444258688161258139001}

def p_num(n):
	d = isqrt(1 + 24 * n)
	return d >= 0 and (int(d) + 1) % 6 == 0


pentagonals = set()
generalized_pentagonals = set([0])
square_pentagonals = set()
for i in range(1, 10 ** 6):
	x = (3 * i ** 2 - i) // 2
	y = (3 * i ** 2 + i) // 2
	pentagonals.add(x)
	generalized_pentagonals.add(x)
	generalized_pentagonals.add(y)
	if (x ** 0.5).is_integer():
		square_pentagonals.add(x)

def p_num(n):
	return n in pentagonals

def g_p_num(n):
	return n in generalized_pentagonals

def s_p_num(n):
	return n in square_pentagonals