Advertisement
ke_timofeeva7

фибоначя

Mar 22nd, 2021
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.16 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <sstream>
  4. #include <cmath>
  5. #include <algorithm>
  6. #include <memory.h>
  7. #include <stdio.h>
  8. #include <vector>
  9. #include <stack>
  10. #include <deque>
  11. #include <queue>
  12. #include <vector>
  13. #include <set>
  14. #include <iterator>
  15. #include <map>
  16. #include <iomanip>
  17. #define int long long
  18. #define fir first
  19. #define sec second
  20. #define sp system("pause")
  21. #define pb push_back
  22. #define double long double
  23. #define endl "\n"
  24. #define un unsigned
  25. using namespace std;
  26.  
  27. int ans[100];
  28. int n, k;
  29.  
  30. void opopo()
  31. {
  32.     ans[0] = 0;
  33.     ans[1] = 2;
  34.     ans[2] = 3;
  35.  
  36.     for (int i = 3; i < n; i++)
  37.     {
  38.         ans[i] = ans[i - 1] + ans[i - 2];
  39.     }
  40.  
  41.     return;
  42. }
  43.  
  44. void out(int n, int k)
  45. {
  46.     if (n <= 0)
  47.     {
  48.         return;
  49.     }
  50.  
  51.     if (n == 1)
  52.     {
  53.         if (k == 1)
  54.         {
  55.             cout << "0";
  56.             return;
  57.         }
  58.         else
  59.         {
  60.             cout << "1";
  61.             return;
  62.         }
  63.     }
  64.  
  65.     if (ans[n - 1] >= k)
  66.     {
  67.         cout << "0";
  68.         out(n - 1, k);
  69.     }
  70.     else
  71.     {
  72.         cout << "10";
  73.         out(n - 2, k - ans[n - 1]);
  74.     }
  75.     return;
  76. }
  77.  
  78. signed main() {
  79.     ios_base::sync_with_stdio();
  80.     cin.tie(0);
  81.     cout.tie(0);
  82.  
  83.     cin >> n >> k;
  84.  
  85.     opopo();
  86.     out(n, k + 1);
  87.     cout << endl;
  88.     //sp;
  89.     return 0;
  90. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement