Skip to content

Instantly share code, notes, and snippets.

@fanzhang312
Created December 4, 2014 05:14
Show Gist options
  • Save fanzhang312/e0b91caf60186d0058bb to your computer and use it in GitHub Desktop.
Save fanzhang312/e0b91caf60186d0058bb to your computer and use it in GitHub Desktop.
Check if a number is a Fibonacci number
public static boolean isFibo(long n){
return isPerfectSquare(5*n*n+4) || isPerfectSquare(5*n*n-4);
}
public static boolean isPerfectSquare(double a){
int s = (int) Math.sqrt(a);
return s*s == a;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment