Advertisement
lorcheiro

Untitled

Apr 8th, 2020
487
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.18 KB | None | 0 0
  1. #include<iostream>
  2. #include<vector>
  3. #include<math.h>
  4.  
  5. using namespace std;
  6.  
  7. typedef unsigned int long long feo;
  8.  
  9. bool isPerfectSquare(int x)
  10. {
  11.     int s = sqrt(x);
  12.     return (s * s == x);
  13. }
  14.  
  15. bool isFibonacci(int n)
  16. {
  17.  
  18.     return isPerfectSquare(5 * n * n + 4) ||
  19.            isPerfectSquare(5 * n * n - 4);
  20. }
  21.  
  22. vector <feo> relleno(vector <feo>& v, feo i){
  23.     v[i] = v[i - 1] + v[i - 2];
  24.     i++;
  25.     if(i < v.size()) return relleno(v, i);
  26.     else return v;
  27. }
  28. vector <bool> casos(vector <bool>& v (pow(10, 5)), feo i, int n){
  29.     i++; //rellenar la posición 0 a mano :D
  30.     int k = i;
  31.     if (isFibonacci(i)) v[i] = true;
  32.     else{
  33.         while(!isFibonacci(k)) k--;
  34.         if(!isFibonacci(i - k) || v[i - k]) v[i] = true;
  35.         else v[i] = false
  36.     }
  37.     if (v.size() < pow(10, 5)) casos(v, i++, n);
  38.     else return v;
  39. }
  40.  
  41.  
  42. int main(){
  43.     vector <feo> fibonacci (pow(10, 5));
  44.     fibonacci[0] = 1;
  45.     fibonacci[1] = 1;
  46.     relleno(fibonacci, 2);
  47.     vector <bool> guanya1 (pow(10, 5));
  48.     feo n;
  49.     guanya1[0] = false;
  50.     guanya1[1] = true;
  51.     while(cin >> n){
  52.         casos(guanya1, 2, n);
  53.         if(isFibonacci(n)) cout << 1 << endl;
  54.         else{
  55.             if(guanya1[n]) cout << 1 << endl;
  56.             else cout << 2 << endl;
  57.         }
  58.  
  59.     }
  60.  
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement