-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathB_Fibonaccharsis.cpp
105 lines (90 loc) · 1.52 KB
/
B_Fibonaccharsis.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define f(i, j, n) for (ll i = j; i < n; i++)
#define fo(i, j) for (auto i : j)
#define vec vector<ll>
ll fibbo(ll n)
{
if (n < 0)
{
return -1;
}
vec dp(n + 1);
dp[0] = 0;
dp[1] = 1;
f(i, 2, n + 1)
{
dp[i] = dp[i - 1] + dp[i - 2];
}
return dp[n];
}
void solve1()
{
ll n, k;
cin >> n >> k;
ll a, b;
if (n % 2 == 0)
{
a = b = n / 2;
}
else
{
a = n / 2;
b = n / 2 + 1;
}
if (a == 0 && b == 0)
{
cout << 0 << endl;
return;
}
ll count = 0;
while (b <= 2 * a)
{
if (a < fibbo(k - 3))
{
cout << count << endl;
return;
}
if (b - a >= fibbo(k - 4))
count++;
b++;
a--;
}
cout << count << endl;
}
void solve()
{
ll n, k, ans = 0;
cin >> n >> k;
if (k >= 29)
{
cout << 0;
return;
}
vector<ll> fibonacci(29, 1);
for (int i = 2; i <= 28; i++)
fibonacci[i] = fibonacci[i - 1] + fibonacci[i - 2];
ll x = fibonacci[k - 3], y = fibonacci[k - 2]; // x=1 , y=2
for (int i = 0; i <= n; i++)
{
ll temp = n - y * i;
if (temp >= 0 and temp % x == 0)
{
if (i >= temp / x)
ans++;
}
}
cout << ans;
}
int main()
{
ll t;
cin >> t;
while (t--)
{
solve();
cout << endl;
}
return 0;
}