AlenAntonelli

fibnacchi

May 12th, 2018
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.69 KB | None | 0 0
  1. https://trello.com/c/cFURddke/105-hackerrank-is-fibo
  2. https://www.hackerrank.com/challenges/is-fibo/problem
  3.  
  4. #include <iostream>     // std::cout
  5. #include <vector>      // std::swap
  6. #include <algorithm>    // std::binary_search, std::sort
  7.  
  8. using namespace std;
  9.  
  10. int main()
  11. {
  12.     int N=50;
  13.     vector <long> f (N+1);
  14.    
  15.     f[0]=0;
  16.     f[1]=1;
  17.    
  18.     for(int i=2; i<=N; i++)
  19.         f[i]=f[i-1]+f[i-2];
  20.    
  21.     int T;
  22.     cin>>T;
  23.    
  24.     for(int i=0; i<T; i++)
  25.     {
  26.         int t;
  27.         cin>>t;
  28.         if ( binary_search (f.begin(), f.end(), t) )
  29.             cout<<"IsFibo"<<endl;
  30.         else
  31.             cout<<"IsNotFibo"<<endl;
  32.     }
  33.    
  34.    
  35.     return 0;
  36. }
Advertisement
Add Comment
Please, Sign In to add comment