C++ he thong
C++ he thong
Bài 1:.................................................................................1
Bài 2:.................................................................................3
Bài 4:.................................................................................7
Bài 1:
#include <bits/stdc++.h>
void Fibo() {
F[0] = 0;
F[1] = 1;
for (int i = 2; i <= 100; i++) {
F[i] = F[i - 2] + F[i - 1];
}
}
int bn(int l, int r, int x) {
while (l <= r) {
int m = (l + r) / 2;
if (F[m] == x) {
return 1;
} else if (F[m] > x) {
r = m - 1;
} else {
l = m + 1;
}
}
return -1;
}
int solve(int& n) {
n++;
while (1) {
if (bn(0, 100, n) == -1) {
return n;
} else {
n++;
}
}
}
int main() {
Fibo();
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
cout << solve(n) << endl;
}
return 0;
}
Bài 2:
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
string s;
cin >> s;
int a, b;
int res = -1;
if (a - b > res) {
res = a - b;
}
}
}
Bài 3:
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
int F1 = 1, F2 = 2, F3 = 3;
while (n > 0) {
F1 = F2;
F2 = F3;
F3 = F1 + F2;
n = n - (F3 - F2 - 1);
}
n = n + (F3 - F2 - 1);
cout << F2 + n << endl;
}
return 0;
}
Bài 4:
#include <bits/stdc++.h>
void Fibo() {
F[0] = 0;
F[1] = 1;
int main() {
Fibo();
int t;
cin >> t;
while (t--) {
long long n;
cin >> n;
long long rs = 0;
return 0;
}