Advertisement
Josif_tepe

Untitled

May 3rd, 2025
199
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.60 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int fib(int n) {
  5.     if(n <= 2) {
  6.         return 1;
  7.     }
  8.     return fib(n - 1) + fib(n - 2);
  9. }
  10. int dali_e_fibonaciev(int N, int i) {
  11.     if(fib(i) == N) {
  12.         return 1;
  13.     }
  14.     if(fib(i) > N) {
  15.         return 0;
  16.     }
  17.     return dali_e_fibonaciev(N, i + 1);
  18. }
  19.  
  20. int rec(int P, int K) {
  21.     if(P > K) {
  22.         return 0;
  23.     }
  24.     int fib = 0;
  25.     if(dali_e_fibonaciev(P, 1)) {
  26.         fib = 1;
  27.     }
  28.     return rec(P + 1, K) + fib;
  29. }
  30. int main() {
  31.     int P, K;
  32.     cin >> P >> K;
  33.     cout << rec(P, K) << endl;
  34.  
  35.     return 0;
  36. }
  37.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement