Created
December 11, 2014 19:08
-
-
Save petomalina/d80f1a9f47288ed3dd5d to your computer and use it in GitHub Desktop.
IsFibo challenge in C++
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*Author: Gelidus(gelidus@hotmail.sk)*/ | |
#include <cmath> | |
#include <cstdio> | |
#include <vector> | |
#include <iostream> | |
#include <algorithm> | |
using namespace std; | |
int main() { | |
/* Enter your code here. Read input from STDIN. Print output to STDOUT */ | |
int testCases; cin >> testCases; | |
double root5 = sqrt(5); | |
double phi = (1 + root5) / 2; | |
for(int i = 0; i < testCases; i++) { | |
long long number; cin >> number; | |
long long id = (long long)floor(log(number * root5) / log(phi) + 0.5); | |
long long u = (long long)floor(pow(phi, id) / root5 + 0.5); | |
cout << (u == number ? "IsFibo" : "IsNotFibo") << endl; | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment