Skip to content

Instantly share code, notes, and snippets.

@petomalina
Created December 11, 2014 19:08
Show Gist options
  • Save petomalina/d80f1a9f47288ed3dd5d to your computer and use it in GitHub Desktop.
Save petomalina/d80f1a9f47288ed3dd5d to your computer and use it in GitHub Desktop.
IsFibo challenge in C++
/*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