tim_ryspekov

Ryspekov's Fibonacci formula C++

Jun 13th, 2017
751
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.45 KB | None | 0 0
  1. #include<iostream>
  2. #include <cmath>
  3. using namespace std;
  4. int zn(int x){
  5.     x=abs(x);
  6.     x+=4;
  7.     x=x/5;
  8.     x=(int)(pow(2.0,x+0.0))%2;
  9.     return x;
  10.  
  11. }
  12. int main(){
  13.     int n,b;
  14.     double x;
  15.     cin>>b;
  16.     b-=1;
  17.     x=1;
  18.     n=2;
  19.     while(n<b){
  20.          n++;
  21.         int k=(int)(x*(1+sqrt(5))/2);
  22.         x=k+zn(n%3)*(k%2)+(1-zn(n%3))*zn(k%2);
  23.         cout<<(int)(x)<<endl;
  24.     }
  25.     x-=zn(b);
  26.     cout<<x;
  27.     return 0;
  28. }
Add Comment
Please, Sign In to add comment