We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
This is my code for the problem isFibo . We are supposed to create a function which would detect if a number is a fibonacci number or not and returns IsFibo if it is one and IsNotFibo otherwise.
But for n >= 28657 which is a fibonacci number this test fails, as p and q are then coming negative. Can someone please say what is wrong with my code?
string isFibo(long n) {
if(n==0)
return "IsFibo";
long long p=5*n*n-4;
long long q=5*n*n+4;
cout<
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Is Fibo
You are viewing a single comment's thread. Return to all comments →
This is my code for the problem isFibo . We are supposed to create a function which would detect if a number is a fibonacci number or not and returns IsFibo if it is one and IsNotFibo otherwise. But for n >= 28657 which is a fibonacci number this test fails, as p and q are then coming negative. Can someone please say what is wrong with my code?
string isFibo(long n) { if(n==0) return "IsFibo"; long long p=5*n*n-4; long long q=5*n*n+4; cout<