Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<vector>
- #include<math.h>
- using namespace std;
- typedef unsigned int long long feo;
- bool isPerfectSquare(int x)
- {
- int s = sqrt(x);
- return (s * s == x);
- }
- bool isFibonacci(int n)
- {
- return isPerfectSquare(5 * n * n + 4) ||
- isPerfectSquare(5 * n * n - 4);
- }
- vector <feo> relleno(vector <feo>& v, feo i){
- v[i] = v[i - 1] + v[i - 2];
- i++;
- if(i < v.size()) return relleno(v, i);
- else return v;
- }
- vector <bool> casos(vector <bool>& v (pow(10, 5)), feo i, int n){
- i++; //rellenar la posición 0 a mano :D
- int k = i;
- if (isFibonacci(i)) v[i] = true;
- else{
- while(!isFibonacci(k)) k--;
- if(!isFibonacci(i - k) || v[i - k]) v[i] = true;
- else v[i] = false
- }
- if (v.size() < pow(10, 5)) casos(v, i++, n);
- else return v;
- }
- int main(){
- vector <feo> fibonacci (pow(10, 5));
- fibonacci[0] = 1;
- fibonacci[1] = 1;
- relleno(fibonacci, 2);
- vector <bool> guanya1 (pow(10, 5));
- feo n;
- guanya1[0] = false;
- guanya1[1] = true;
- while(cin >> n){
- casos(guanya1, 2, n);
- if(isFibonacci(n)) cout << 1 << endl;
- else{
- if(guanya1[n]) cout << 1 << endl;
- else cout << 2 << endl;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement