fork download
  1. // وَأَن لَّيْسَ لِلْإِنسَانِ إِلَّا مَا سَعَىٰ (39) وَأَنَّ سَعْيَهُ سَوْفَ يُرَىٰ (40)
  2.  
  3. /*
  4.   author: Mazen Mohamed
  5.   */
  6. #include <bits/stdc++.h>
  7. #include <ext/pb_ds/assoc_container.hpp>
  8. #include <ext/pb_ds/tree_policy.hpp>
  9.  
  10. using namespace std;
  11. using namespace __gnu_pbds;
  12. using ll = long long;
  13. using ld = long double;
  14.  
  15. #define all(x) x.begin(),x.end()
  16. #define v(x) vector<x>
  17. #define nl '\n'
  18. #define sp ' '
  19. #define fxd(x) fixed << setprecision(x)
  20. template<class t> using ordered_set = tree<t, null_type, less<t>, rb_tree_tag, tree_order_statistics_node_update>;
  21. template<class t> using ordered_multiset = tree<t, null_type, less_equal<t>, rb_tree_tag, tree_order_statistics_node_update>;
  22.  
  23. ll mod = 1e9 + 7;
  24. ld pi = acos(-1);
  25.  
  26. ll dr[8] = {0, 0, 1, -1, 1, 1, -1, -1};
  27. ll dc[8] = {1, -1, 0, 0, 1, -1, 1, -1};
  28.  
  29. int n;
  30. vector<ll> arr;
  31. unordered_set<ll> st;
  32.  
  33. int ln(int i , int j)
  34. {
  35. ll fr = i;
  36. ll sc = j;
  37. if(fr + sc == 0 ) return 2;
  38. int curlen = 2;
  39. while (true)
  40. {
  41. if(st.count(fr+sc) == 1)
  42. {
  43. int te = sc + fr;
  44. fr = sc;
  45. sc = te;
  46. curlen++;
  47. }
  48. else
  49. {
  50. return curlen;
  51. }
  52. }
  53.  
  54. }
  55.  
  56. void hankasha()
  57. {
  58. cin >> n;
  59. arr.assign(n,0);
  60. st.clear();
  61. for (int i = 0; i < n; i++)
  62. {
  63. cin >> arr[i];
  64. st.insert(arr[i]);
  65. }
  66.  
  67. sort(all(arr));
  68. int ans = 2;
  69. for (int i = 0; i < n; i++)
  70. {
  71. for (int j = 0 ; j < n; j++)
  72. {
  73. if(i == j) continue;
  74. ans = max(ans,ln(arr[i],arr[j]));
  75. }
  76.  
  77. }
  78. cout << ans << nl;
  79. }
  80.  
  81.  
  82. int main()
  83. {
  84. ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
  85.  
  86. int t = 1;
  87. cin >> t;
  88. while (t--)
  89. {
  90. hankasha();
  91. }
  92. }
Success #stdin #stdout 0s 544KB
stdin
Standard input is empty
stdout
2