Given a number N. Find out the nearest number which is a perfect square and also the absolute difference between them.
Example 1:
Input:
N = 25
Output:
25 0
Explanation:
Since 25 is a perfect square, it is the 
closest perfect square to itself and 
absolute difference is 25-25=0.
Example 2:
Input:
N = 1500
Output:
1521 21
Explanation:
Two of the closest perfect squares to 
1521 are 1444.Thus, 1521 is the closest 
perfect square to 1500 and the absolute 
difference  between them is 1521-1500=21.
Your Task:
You don't need to read input or print anything.Your Task is to complete the function nearestPerfectSquare() which takes the number N as input parameters and returns the nearest perfect square as well as the absolute difference between them.
Expected Time Complexity:O(sqrt(N))
Expected Space Auxillary:O(1)
Constraints:
1<=N<=10^{9}

Source: geeksforgeeks | Difficulty: EASY
Tags: Mathematics

Starter code: #User function Template for python3



class Solution:

    def nearestPerfectSquare(self,N):

        #code here(return list of two numbers)

Solutions:
class Solution:

	def nearestPerfectSquare(self, N):
		import math
		b = int(math.sqrt(N))
		s1 = b ** 2
		s2 = (b + 1) ** 2
		d1 = N - s1
		d2 = s2 - N
		if d1 < d2:
			return (s1, d1)
		return (s2, d2)


class Solution:

	def nearestPerfectSquare(self, N):
		i = 1
		while i * i < N:
			i += 1
		closest_square = i * i
		i = 1
		while i * i <= N:
			i += 1
		closest_square2 = (i - 1) * (i - 1)
		diff1 = closest_square - N
		diff2 = N - closest_square2
		if diff1 <= diff2:
			return [closest_square, diff1]
		else:
			return [closest_square2, diff2]


class Solution:

	def nearestPerfectSquare(self, N):
		b = int(N ** 0.5)
		s1 = b ** 2
		s2 = (b + 1) ** 2
		d1 = N - s1
		d2 = s2 - N
		if d1 < d2:
			return (s1, d1)
		return (s2, d2)


class Solution:

	def nearestPerfectSquare(self, N):
		if int(N ** 0.5) * int(N ** 0.5) == N:
			return (N, 0)
		i = N
		d = N
		c = []
		while N > 0:
			i = i + 1
			if int(i ** 0.5) * int(i ** 0.5) == i:
				c.append(N)
				break
		while N > 0:
			d = d - 1
			if int(d ** 0.5) * int(d ** 0.5) == d:
				c.append(d)
				break
		if i - N < N - d:
			return (i, i - N)
		else:
			return (d, N - d)


import math

class Solution:

	def nearestPerfectSquare(self, N):
		b = int(math.sqrt(N))
		s1 = b ** 2
		s2 = (b + 1) ** 2
		x = abs(N - s1)
		y = abs(s2 - N)
		if x < y:
			return (s1, x)
		return (s2, y)


import math

class Solution:

	def checkPerfectSquare(N):
		x = int(math.sqrt(N))
		if x * x == N:
			return 1
		return 0

	def nearestPerfectSquare(self, N):
		minAns = N
		sqVal = N
		ansv = []
		if Solution.checkPerfectSquare(N):
			ansv.append(N)
			ansv.append(0)
			return ansv
		for i in range(int(math.sqrt(N))):
			subi = N - i
			addi = N + i
			if Solution.checkPerfectSquare(subi):
				ansv.append(subi)
				ansv.append(i)
				return ansv
			if Solution.checkPerfectSquare(addi):
				ansv.append(addi)
				ansv.append(i)
				return ansv


class Solution:

	def nearestPerfectSquare(self, n):
		if n ** 0.5 == int(n ** 0.5):
			return (n, 0)
		k = int(n ** 0.5)
		if n - k ** 2 < (k + 1) ** 2 - n:
			return (k ** 2, n - k ** 2)
		return ((k + 1) ** 2, (k + 1) ** 2 - n)


import math

class Solution:

	def nearestPerfectSquare(self, N):
		num1 = int(math.sqrt(N))
		num2 = (num1 + 1) ** 2
		num1 = num1 ** 2
		if num2 - N < N - num1:
			return [num2, num2 - N]
		return [num1, N - num1]


from math import *

class Solution:

	def nearestPerfectSquare(self, n):
		(x, y) = (floor(sqrt(n)) ** 2, ceil(sqrt(n)) ** 2)
		(a, b) = (n - x, y - n)
		if a <= b:
			return [x, a]
		return [y, b]


import math

class Solution:

	def nearestPerfectSquare(self, N):
		above = math.ceil(N ** (1 / 2))
		below = math.floor(N ** (1 / 2))
		max_diff = abs(N - above ** 2)
		min_diff = abs(N - below ** 2)
		if max_diff < min_diff:
			return (above ** 2, max_diff)
		return (below ** 2, min_diff)


class Solution:

	def nearestPerfectSquare(self, N):
		a1 = []
		a = int(N ** 0.5)
		b = a + 1
		if a ** 2 == N:
			a1.append(N)
			a1.append(0)
			return a1
		if N - a ** 2 > b ** 2 - N:
			b = b ** 2
			a1.append(b)
			b = b - N
			a1.append(b)
			return a1
		a = a ** 2
		a1.append(a)
		a = N - a
		a1.append(a)
		return a1


class Solution:

	def nearestPerfectSquare(self, N):
		sqr = N ** 0.5
		if sqr - int(sqr) >= 0.5:
			nsr = int(sqr) + 1
		else:
			nsr = int(sqr)
		return [nsr * nsr, abs(N - nsr * nsr)]


import math

class Solution:

	def nearestPerfectSquare(self, N):
		n = int(math.sqrt(N))
		a = n * n
		b = (n + 1) ** 2
		c = N - a
		d = b - N
		if c < d:
			return (a, c)
		return (b, d)


import math

class Solution:

	def nearestPerfectSquare(self, n):
		ps = math.floor(math.sqrt(n))
		a = ps * ps
		b = (ps + 1) * (ps + 1)
		li = []
		if n - a < b - n:
			li.append(a)
		else:
			li.append(b)
		di = abs(li[0] - n)
		li.append(di)
		return li


from math import sqrt, floor

class Solution:

	def nearestPerfectSquare(self, N):
		s = floor(sqrt(N))
		if sqrt(N) - floor(sqrt(N)) == 0:
			return (N, 0)
		aboveN = (s + 1) * (s + 1)
		belowN = s * s
		diff1 = aboveN - N
		diff2 = N - belowN
		if diff1 < diff2:
			return (aboveN, diff1)
		else:
			return (belowN, diff2)


class Solution:

	def nearestPerfectSquare(self, N):
		r = int(N ** 0.5)
		r1 = r ** 2
		r2 = (r + 1) ** 2
		d1 = N - r1
		d2 = r2 - N
		if d1 < d2:
			return (r1, d1)
		else:
			return (r2, d2)


class Solution:

	def nearestPerfectSquare(self, n):
		k = int(n ** 0.5)
		a = k * k
		b = (k + 1) * (k + 1)
		if abs(a - n) > abs(b - n):
			return [b, abs(b - n)]
		else:
			return [a, abs(a - n)]


class Solution:

	def nearestPerfectSquare(self, N):
		i = 1
		while i ** 2 <= N:
			t1 = i ** 2
			i += 1
		t2 = i ** 2
		if abs(t2 - N) > abs(N - t1):
			return (t1, abs(N - t1))
		else:
			return (t2, abs(t2 - N))


import math

class Solution:

	def nearestPerfectSquare(self, N):
		near_square = round(math.sqrt(N))
		return [near_square ** 2, abs(near_square ** 2 - N)]


import math

class Solution:

	def nearestPerfectSquare(self, N):
		num = math.sqrt(N)
		n = round(num, 0)
		n2 = int(n ** 2)
		if n > num:
			return (n2, n2 - N)
		else:
			return (n2, N - n2)


import math

class Solution:

	def nearestPerfectSquare(self, N):
		x = math.floor(math.sqrt(N))
		if x == math.sqrt(N):
			return [N, 0]
		else:
			above = (x + 1) * (x + 1)
			below = x * x
			if above - N > N - below:
				return [below, N - below]
			else:
				return [above, above - N]


import math

class Solution:

	def nearestPerfectSquare(self, N):
		a = int(math.sqrt(N))
		num1 = a ** 2
		num2 = (a + 1) ** 2
		diff1 = N - num1
		diff2 = num2 - N
		if diff1 < diff2:
			return (num1, diff1)
		return (num2, diff2)


class Solution:

	def nearestPerfectSquare(self, N):
		n = int(N ** 0.5)
		l = 2 * n + 1
		n *= n
		if n == N:
			return (n, 0)
		if 2 * N < 2 * n + l:
			return (n, N - n)
		return (n + l, n + l - N)


import math

class Solution:

	def nearestPerfectSquare(self, n):
		root = math.sqrt(N)
		lower = math.floor(root)
		upper = math.ceil(root)
		ans = [0] * 2
		if upper - root <= root - lower:
			ans[0] = int(upper * upper)
		else:
			ans[0] = int(lower * lower)
		ans[1] = abs(ans[0] - N)
		return ans


class Solution:

	def nearestPerfectSquare(self, N):
		import math
		x = math.sqrt(N)
		floor = math.floor(x)
		ceil = math.ceil(x)
		if abs(floor - x) > abs(ceil - x):
			x = ceil
		else:
			x = floor
		new = x * x
		ans = abs(N - new)
		return [new, ans]


import math

class Solution:

	def nearestPerfectSquare(self, N):
		Floor = math.floor(math.sqrt(N))
		Ceil = math.ceil(math.sqrt(N))
		if N - Floor * Floor < Ceil * Ceil - N:
			return [Floor * Floor, N - Floor * Floor]
		return [Ceil * Ceil, Ceil * Ceil - N]


import math

class Solution:

	def nearestPerfectSquare(self, N):
		a = math.sqrt(N)
		(c, f) = (math.ceil(a) * math.ceil(a), math.floor(a) * math.floor(a))
		if c - N <= N - f:
			return (c, c - N)
		return (f, N - f)


class Solution:

	def nearestPerfectSquare(self, N):
		n = N ** (1 / 2)
		if int(n) == n:
			return [N, 0]
		else:
			if n >= int(n) + 1 / 2:
				return [(int(n) + 1) ** 2, (int(n) + 1) ** 2 - N]
			return [int(n) ** 2, N - int(n) ** 2]


class Solution:

	def nearestPerfectSquare(self, N):
		sqrt = N ** 0.5
		sqrint = int(sqrt)
		sqrinta = sqrint + 1
		if N - sqrint ** 2 <= sqrinta ** 2 - N:
			a = sqrint
		else:
			a = sqrinta
		return [a ** 2, abs(a ** 2 - N)]


from math import *

class Solution:

	def nearestPerfectSquare(self, N):
		a = ceil(sqrt(N))
		b = floor(sqrt(N))
		c = a * a
		d = b * b
		if abs(c - N) < abs(d - N):
			return (c, abs(c - N))
		else:
			return (d, abs(d - N))


import math

class Solution:

	def nearestPerfectSquare(self, n):
		s = int(math.sqrt(n))
		pr = s ** 2
		su = (s + 1) ** 2
		d1 = n - pr
		d2 = su - n
		if d1 < d2:
			return (pr, d1)
		return (su, d2)


class Solution:

	def nearestPerfectSquare(self, N):
		lst = []
		d = N ** 0.5
		k = round(d)
		k = k ** 2
		d = abs(k - N)
		lst.append(k)
		lst.append(d)
		return lst


import math

class Solution:

	def nearestPerfectSquare(self, N):
		i = [int(math.sqrt(N)), 0, 0, 0, 0]
		i[1] = i[0] ** 2
		if i[1] == N:
			return [N, 0]
		else:
			i[2] = (i[0] + 1) ** 2
			i[3] = abs(i[1] - N)
			i[4] = abs(i[2] - N)
			if i[3] < i[4]:
				return [i[1], i[3]]
			else:
				return [i[2], i[4]]
if __name__ == '__main__':
	t = int(input())
	for _ in range(t):
		N = int(input())
		ob = Solution()
		ans = ob.nearestPerfectSquare(N)
		print(ans[0], ans[1])


class Solution:

	def nearestPerfectSquare(self, N):
		b = int(N ** 0.5)
		s1 = b ** 2
		s2 = (b + 1) ** 2
		d1 = N - s1
		d2 = s2 - N
		if d1 < d2:
			return (s1, d1)
		return (s2, d2)
if __name__ == '__main__':
	t = int(input())
	for _ in range(t):
		N = int(input())
		ob = Solution()
		ans = ob.nearestPerfectSquare(N)
		print(ans[0], ans[1])


import math

class Solution:

	def nearestPerfectSquare(self, N):
		k1 = math.floor(N ** 0.5)
		k2 = math.ceil(N ** 0.5)
		if k1 == k2:
			return [N, 0]
		if N - k1 ** 2 > k2 ** 2 - N:
			return [k2 ** 2, k2 ** 2 - N]
		return [k1 ** 2, N - k1 ** 2]
if __name__ == '__main__':
	t = int(input())
	for _ in range(t):
		N = int(input())
		ob = Solution()
		ans = ob.nearestPerfectSquare(N)
		print(ans[0], ans[1])


class Solution:

	def nearestPerfectSquare(self, N):
		import math
		b = int(math.sqrt(N))
		s1 = int(math.pow(b, 2))
		s2 = int(math.pow(b + 1, 2))
		d1 = abs(N - s1)
		d2 = abs(N - s2)
		if d1 < d2:
			return (s1, d1)
		return (s2, d2)
if __name__ == '__main__':
	t = int(input())
	for _ in range(t):
		N = int(input())
		ob = Solution()
		ans = ob.nearestPerfectSquare(N)
		print(ans[0], ans[1])


class Solution:

	def nearestPerfectSquare(self, N):
		d = int(N ** 0.5)
		f = d * d
		e = N - f
		g = (d + 1) * (d + 1)
		if g - N < e:
			return [g, g - N]
		return [f, e]
if __name__ == '__main__':
	t = int(input())
	for _ in range(t):
		N = int(input())
		ob = Solution()
		ans = ob.nearestPerfectSquare(N)
		print(ans[0], ans[1])


import math

class Solution:

	def nearestPerfectSquare(self, N):
		sq = int(math.sqrt(N))
		if sq * sq == N:
			return [N, 0]
		else:
			low = sq
			high = sq + 1
			if N - low * low < high * high - N:
				return [low * low, abs(N - low * low)]
			else:
				return [high * high, abs(N - high * high)]


import math

class Solution:

	def nearestPerfectSquare(self, N):
		near_ele1 = math.floor(math.sqrt(N))
		near_ele2 = math.ceil(math.sqrt(N))
		sub1 = abs(N - near_ele1 * near_ele1)
		sub2 = abs(N - near_ele2 * near_ele2)
		if sub1 > sub2:
			return [near_ele2 * near_ele2, sub2]
		else:
			return [near_ele1 * near_ele1, sub1]


from math import *

class Solution:

	def nearestPerfectSquare(self, N):
		sr = round(sqrt(N))
		return [sr ** 2, abs(sr ** 2 - N)]


from math import floor, sqrt

class Solution:

	def nearestPerfectSquare(self, n):
		if sqrt(n) - floor(sqrt(n)) == 0:
			return [n, 0]
		x = int(sqrt(n))
		abovesq = (x + 1) ** 2
		belowsq = x ** 2
		diff1 = abovesq - n
		diff2 = n - belowsq
		if diff1 > diff2:
			return [belowsq, diff2]
		else:
			return [abovesq, diff1]


import math

class Solution:

	def nearestPerfectSquare(self, N):
		k = int(math.sqrt(N))
		t = []
		if N - k ** 2 < (k + 1) ** 2 - N:
			t.append(k ** 2)
			t.append(N - k ** 2)
		elif k == math.sqrt(N):
			t.append(N)
			t.append(0)
		else:
			t.append((k + 1) ** 2)
			t.append((k + 1) ** 2 - N)
		return t


import math

class Solution:

	def nearestPerfectSquare(self, N):
		a = math.sqrt(N)
		b = int(a)
		if a == b:
			return [N, 0]
		else:
			c = (b + 1) ** 2
			d = (b - 1) ** 2
			diff1 = abs(c - N)
			diff2 = abs(d - N)
			e = b ** 2
			diff3 = abs(e - N)
			final_diff = min(diff1, diff2, diff3)
			if N + final_diff == c:
				return [c, final_diff]
			elif N + final_diff == d:
				return [d, final_diff]
			else:
				return [e, final_diff]


import math

class Solution:

	def nearestPerfectSquare(self, N):
		res = []
		sqr = math.sqrt(N)
		if sqr ** 2 == int(sqr) ** 2:
			res.append(N)
			res.append(0)
		if abs(int(sqr) ** 2 - N) < abs(int(sqr) + 1) ** 2 - N:
			res.append(int(sqr) ** 2)
			res.append(abs(int(sqr) ** 2 - N))
		else:
			res.append((int(sqr) + 1) ** 2)
			res.append(abs(int(sqr) + 1) ** 2 - N)
		return res


class Solution:

	def nearestPerfectSquare(self, N):
		res = []
		k = N ** (1 / 2)
		l = int(k)
		if abs(k - l) == 0:
			res.append(N)
			res.append(0)
			return res
		x = (l + 1) * (l + 1)
		y = l * l
		if abs(x - N) > abs(y - N):
			res.append(y)
			res.append(abs(y - N))
			return res
		else:
			res.append(x)
			res.append(abs(x - N))
			return res


from math import sqrt, floor

class Solution:

	def nearestPerfectSquare(self, N):
		x = floor(sqrt(N))
		if x == sqrt(N):
			return [N, 0]
		abo = (x + 1) * (x + 1)
		bel = x * x
		dif1 = abo - N
		dif2 = N - bel
		if dif1 > dif2:
			return [bel, dif2]
		return [abo, dif1]


from math import sqrt

class Solution:

	def nearestPerfectSquare(self, N):
		temp = int(sqrt(N))
		a = int((temp + 1) ** 2)
		b = int(temp ** 2)
		if N - b > a - N:
			return [a, a - N]
		else:
			return [b, N - b]


class Solution:

	def nearestPerfectSquare(self, N):
		temp = int(N ** 0.5)
		a = int((temp + 1) ** 2)
		b = int(temp ** 2)
		if N - b > a - N:
			return [a, a - N]
		else:
			return [b, N - b]


import math

class Solution:

	def nearestPerfectSquare(self, N):
		t = int(math.sqrt(N))
		p = t ** 2
		q = (t + 1) ** 2
		a = N - p
		b = q - N
		if a < b:
			return (p, a)
		else:
			return (q, b)


import sys
import heapq
import math
from collections import defaultdict as dd
from itertools import permutations as pp
from itertools import combinations as cc
from collections import Counter
from random import randint as rd
from bisect import bisect_left as bl
from bisect import bisect as bb
mod9 = 10 ** 9 + 7
mod5 = 10 ** 5 + 7

def inty():
	return int(input())

def listy():
	return list(map(int, input().split()))

def mapy():
	return map(int, input().split())

def h(li):
	return heapq.heapify(li)

def hpu(li, n):
	return heapq.heappush(li, n)

def hpo(li):
	return heapq.heappop(li)

def hpp(li, n):
	return heapq.heappushpop(li, n)

def hrpp(li, n):
	return heapq.heapreplace(li, n)

class Solution:

	def nearestPerfectSquare(self, n):
		k = math.ceil(2 ** (math.log(n) / math.log(2) / 2))
		mindist = mod9
		res = 0
		if n == 1:
			return 0
		for j in range(k - 2, k + 3):
			diff = abs(n - j ** 2)
			if diff <= mindist:
				mindist = diff
				res = j
		return [res ** 2, mindist]


import math

class Solution:

	def nearestPerfectSquare(self, N):
		t1 = math.floor(N ** 0.5)
		t2 = math.ceil(N ** 0.5)
		x1 = N - t1 ** 2
		x2 = t2 ** 2 - N
		if x1 < x2:
			return (t1 ** 2, x1)
		else:
			return (t2 ** 2, x2)


import math

class Solution:

	def nearestPerfectSquare(self, N):
		root = int(math.floor(math.sqrt(N)))
		min2 = root ** 2
		max2 = (root + 1) ** 2
		if N - min2 < max2 - N:
			return (int(min2), int(N - min2))
		else:
			return (int(max2), int(max2 - N))


import math

class Solution:

	def nearestPerfectSquare(self, N):
		if N == int(math.sqrt(N)) ** 2:
			return (N, 0)
		n = math.sqrt(N)
		p = math.floor(n)
		q = math.ceil(n)
		x = N - p ** 2
		y = abs(N - q ** 2)
		if x < y:
			return (p * p, x)
		else:
			return (q * q, y)


class Solution:

	def nearestPerfectSquare(self, n):
		a = round(n ** 0.5)
		a *= a
		return (a, abs(a - n))


from math import *

class Solution:

	def nearestPerfectSquare(self, N):
		z = sqrt(N)
		a = int(sqrt(N))
		if a * a == N and a == z:
			return (N, 0)
		else:
			b = int(sqrt(N))
			c = (b + 1) * (b + 1)
			t = b * b
			q = N - t
			w = c - N
			if w < q:
				return (c, w)
			else:
				return (t, q)


import math

class Solution:

	def nearestPerfectSquare(self, N):
		l = []
		a = int(math.sqrt(N))
		if a * a == N:
			l.append(a * a)
			l.append(0)
		else:
			m = abs(a * a - N)
			n = abs((a + 1) * (a + 1) - N)
			if m < n:
				l.append(a * a)
				l.append(abs(a * a - N))
			else:
				l.append((a + 1) * (a + 1))
				l.append(abs((a + 1) * (a + 1) - N))
		return l


import math

class Solution:

	def nearestPerfectSquare(self, N):
		l = []
		q = int(math.sqrt(N))
		if q * q == N:
			l.append(q * q)
			l.append(0)
			return l
		if q * q < N:
			p = abs((q + 1) * (q + 1) - N)
			h = abs(q * q - N)
			if p > h:
				l.append(q * q)
				l.append(h)
			else:
				l.append((q + 1) * (q + 1))
				l.append(p)
		return l


import math as m

class Solution:

	def nearestPerfectSquare(self, N):
		if int(m.sqrt(N)) * int(m.sqrt(N)) == N:
			return [N, 0]
		else:
			l = []
			x = int(m.sqrt(N))
			l.append(x * x)
			l.append((x - 1) * (x - 1))
			l.append((x + 1) * (x + 1))
			x = 0
			y = 99999999999999999
			for i in l:
				if y > abs(i - N):
					x = i
					y = abs(i - N)
			return [x, y]


class Solution:

	def nearestPerfectSquare(self, N):
		j = int(N ** 0.5)
		if abs(j ** 2 - N) < abs((j + 1) ** 2) - N:
			return (j ** 2, abs(j ** 2 - N))
		else:
			return ((j + 1) ** 2, abs((j + 1) ** 2 - N))


import math

class Solution:

	def nearestPerfectSquare(self, N):
		ceiling = math.ceil(N ** (1 / 2)) ** 2
		flooring = math.floor(N ** (1 / 2)) ** 2
		d1 = ceiling - N
		d2 = N - flooring
		if d1 < d2:
			return (ceiling, d1)
		return (flooring, d2)


class Solution:

	def nearestPerfectSquare(self, N):
		import math
		b = int(math.sqrt(N))
		if b * b == N:
			return [N, 0]
		f = b * b
		h = (b + 1) * (b + 1)
		diff1 = abs(f - N)
		diff2 = abs(h - N)
		if diff1 < diff2:
			return [f, diff1]
		return [h, diff2]


class Solution:

	def nearestPerfectSquare(self, N):
		a = round(N ** 0.5)
		ans = []
		ans.append(a ** 2)
		ans.append(abs(a ** 2 - N))
		return ans


import math

class Solution:

	def nearestPerfectSquare(self, N):
		min = 0
		x = round(math.sqrt(N))
		if abs(N - x ** 2) < abs(N - (x - 1) ** 2):
			return [x ** 2, abs(N - x ** 2)]
		else:
			return [(x - 1) ** 2, abs(N - (x - 1) ** 2)]


class Solution:

	def nearestPerfectSquare(self, n):
		s1 = int(n ** 0.5)
		s2 = (s1 + 1) * (s1 + 1)
		s1 = s1 * s1
		l = []
		if n - s1 < s2 - n:
			l.append(s1)
			l.append(n - s1)
		else:
			l.append(s2)
			l.append(s2 - n)
		return l


import math

class Solution:

	def nearestPerfectSquare(self, N):
		sqrt = N ** (1 / 2)
		above = math.ceil(sqrt)
		below = math.floor(sqrt)
		d1 = above ** 2 - N
		d2 = N - below ** 2
		if d1 >= d2:
			return (below ** 2, d2)
		return (above ** 2, d1)


import math

class Solution:

	def nearestPerfectSquare(self, N):
		no = math.sqrt(N)
		sm = math.floor(no)
		la = math.ceil(no)
		if abs(sm * sm - N) > abs(la * la - N):
			return [la * la, abs(la * la - N)]
		return [sm * sm, abs(sm * sm - N)]


import math
from math import sqrt, floor

class Solution:

	def isPerfect(self, n):
		return sqrt(n) == floor(sqrt(n))

	def nearestPerfectSquare(self, N):
		if self.isPerfect(N):
			return [N, 0]
		upper = floor(sqrt(N)) + 1
		upper = upper * upper
		lower = floor(sqrt(N))
		lower = lower * lower
		if upper - N < N - lower:
			return [upper, upper - N]
		else:
			return [lower, N - lower]


class Solution:

	def nearestPerfectSquare(self, N):
		sqroot = int(N ** 0.5)
		if sqroot ** 2 == N:
			return [N, 0]
		mindiff = abs(sqroot ** 2 - N)
		minnum = sqroot
		if mindiff > abs((sqroot - 1) ** 2 - N):
			mindiff = abs((sqroot - 1) ** 2 - N)
			minnum = sqroot - 1
		if mindiff > abs((sqroot + 1) ** 2 - N):
			mindiff = abs((sqroot + 1) ** 2 - N)
			minnum = sqroot + 1
		return [minnum ** 2, mindiff]


import math

class Solution:

	def nearestPerfectSquare(self, N):
		n = math.sqrt(N)
		if n * 10 % 10 == 0:
			return [N, 0]
		else:
			f = math.floor(n)
			c = math.ceil(n)
			cn = abs(c ** 2 - N)
			fn = abs(N - f ** 2)
			if cn > fn:
				return [f ** 2, fn]
			return [c ** 2, cn]