From c83bdd36e8bb308519a96b94305f7d0b60f6dff3 Mon Sep 17 00:00:00 2001 From: NatanLucena <44265910+NatanLucena@users.noreply.github.com> Date: Tue, 22 Oct 2019 16:57:53 -0300 Subject: [PATCH] Create CheckFibonacci.py --- allalgorithms/numeric/CheckFibonacci.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 allalgorithms/numeric/CheckFibonacci.py diff --git a/allalgorithms/numeric/CheckFibonacci.py b/allalgorithms/numeric/CheckFibonacci.py new file mode 100644 index 0000000..271071f --- /dev/null +++ b/allalgorithms/numeric/CheckFibonacci.py @@ -0,0 +1,18 @@ +# -*- coding: UTF-8 -*- +# +# Check fibonacci number +# The All â–²lgorithms library for python +# +# Contributed by: Natan Lucena +# Github: @NatanLucena +# + +import math + +def isPerfectSquare(x): + s = int(math.sqrt(x)) + return s*s == x + +def isFibonacci(n): + + return isPerfectSquare(5*n*n + 4) or isPerfectSquare(5*n*n - 4)