fork download
  1. #include<bits/stdc++.h>
  2. #define f1(i, n) for(int i=1;i<=n;++i)
  3. #define f0(i, n) for(int i=0;i<n;++i)
  4. #define ull unsigned long long
  5. #define ll long long
  6. #define rev(a) reverse(a.begin(),a.end())
  7. #define all(x) x.begin(),x.end()
  8. #define so(A, n) sort(A+1, A+n+1)
  9. using namespace std;
  10. const int maxn = 3e5 + 1;
  11. ll fi[100], A[maxn], size_fi = 0;
  12. map<int, int> mp;
  13. void tao() {
  14. fi[1] = fi[2] = 1;
  15. for (int i = 3; fi[i - 1] <= 1e9; ++i) {
  16. fi[i] = fi[i - 1] + fi[i - 2];
  17. ++size_fi;
  18. }
  19. }
  20. // neu A[i] = 1 thi A[i+1] co the = 1 hoac ko
  21. bool checkFi(int l, int r) {
  22. int iterFi = lower_bound(fi + 1, fi + size_fi + 1, A[l]) - fi;
  23. int cnt1 = 0;
  24. if(A[l] == 1 && A[l+1] != 1) iterFi++;
  25. for (int i = l; i <= r; ++i) {
  26. if (A[i] == 1) {
  27. ++cnt1;
  28. if (cnt1 > 2) {
  29. return false;
  30. }
  31. }
  32. if (fi[iterFi] != A[i]) {
  33. return false;
  34. }
  35. ++iterFi;
  36. }
  37. return true;
  38. }
  39. int main() {
  40. ios_base::sync_with_stdio(0);
  41. cin.tie(0);
  42. cout.tie(0);
  43. tao();
  44. int n;
  45. cin >> n;
  46. f1(i, n) {
  47. cin >> A[i];
  48. mp[A[i]]++;
  49. }
  50. if (mp[A[1]] == n) {
  51. if (binary_search(fi + 1, fi + size_fi + 1, A[1])) {
  52. if (A[1] == 1) cout << 2 * n - 1;
  53. else cout << n;
  54. }
  55. else {
  56. cout << 0;
  57. }
  58. return 0;
  59. }
  60. int res = 0;
  61. for (int i = 1; i <= n; ++i) {
  62. for (int j = i; j <= n; ++j) {
  63. if (binary_search(fi + 1, fi + size_fi + 1, A[i])) {
  64. if (checkFi(i, j)) {
  65. ++res;
  66. }
  67. }
  68. }
  69. }
  70. cout << res;
  71.  
  72.  
  73. return 0;
  74.  
  75.  
  76. }
  77.  
Success #stdin #stdout 0.01s 5288KB
stdin
Standard input is empty
stdout
Standard output is empty