• Source
    1. #include <iostream>
    2. #include <vector>
    3. #include <algorithm>
    4. #include <string>
    5. using namespace std;
    6. struct bigInt
    7. {
    8. vector<int> a;
    9. bigInt()
    10. {
    11. a.push_back(0);
    12. }
    13. bigInt(int x)
    14. {
    15. if(x==0)
    16. a.push_back(0);
    17. while(x!=0)
    18. {
    19. a.push_back(x%10);
    20. x=x/10;
    21. }
    22. }
    23. void operator += (const bigInt& b)
    24. {
    25. vector<int> x,y,z;
    26. x=a;
    27. y=b.a;
    28. int n=x.size();
    29. int m=y.size();
    30. if(n<m)
    31. for(int i=0;i<m-n;++i)
    32. x.push_back(0);
    33. else
    34. for(int i=0;i<n-m;++i)
    35. y.push_back(0);
    36. int h=0;
    37. for(int i=0;i<x.size();++i)
    38. {
    39. z.push_back(x[i]+y[i]+h);
    40. h=z[i]/10;
    41. z[i]%=10;
    42. }
    43. if(h==1)
    44. z.push_back(1);
    45. while(z[z.size()-1]==0)
    46. z.pop_back();
    47. a=z;
    48.  
    49. }
    50. void operator -=( const bigInt& b)
    51. {
    52. for(int i=0;i<b.a.size();++i)
    53. {
    54. a[i]-=b.a[i];
    55. if(a[i]<0)
    56. {
    57. a[i]+=10;
    58. int j=i+1;
    59. while(a[j]==0)
    60. {
    61. a[j]=9;
    62. ++j;
    63. }
    64. --a[j];
    65. }
    66. }
    67. while(a[a.size()-1]==0 && a.size()!=1)
    68. a.pop_back();
    69. }
    70. bigInt multByDigit(const bigInt& b,int x)
    71. {
    72. bigInt ans;
    73. vector<int> res;
    74. int h=0;
    75. for(int i=0;i<b.a.size();++i)
    76. {
    77. res.push_back( b.a[i]*x+h);
    78. h=res[res.size()-1]/10;
    79. res[res.size()-1]%=10;
    80. }
    81. if(h!=0)
    82. res.push_back(h);
    83. ans.a=res;
    84. return ans;
    85. }
    86. void operator *=( const bigInt& b)
    87. {
    88. bigInt ans;
    89. for(int i=0;i<b.a.size();++i)
    90. {
    91. vector<int> c;
    92. for(int j=0;j<i;++j)
    93. c.push_back(0);
    94. bigInt d;
    95. d=d.multByDigit(*this,b.a[i]);
    96. for(int j=0;j<d.a.size();++j)
    97. c.push_back(d.a[j]);
    98. bigInt temp;
    99. temp.a=c;
    100. ans+=temp;
    101. }
    102. *this=ans;
    103. }
    104. bigInt half( const bigInt& bb)
    105. {
    106. vector<int> ans;
    107. bigInt b=bb;
    108. int i=b.a.size()-1;
    109. while(i>=0)
    110. {
    111. if(b.a[i]%2==0)
    112. {
    113. if(i!=0)
    114. ans.push_back(b.a[i]/2);
    115. --i;
    116. }
    117. else
    118. {
    119. if(b.a[i]!=1)
    120. {
    121. ans.push_back(b.a[i]/2);
    122. b.a[i]=1;
    123. }
    124. else
    125. {
    126.  
    127. int x=b.a[i];
    128. if(i-1>=0)
    129. x=x*10+b.a[i-1];
    130. if(i!=0)
    131. ans.push_back(x/2);
    132. --i;
    133. if(i-1>=0)
    134. b.a[i]=1;
    135. }
    136. }
    137. }
    138. bigInt res;
    139. reverse(ans.begin(),ans.end());
    140. res.a=ans;
    141. return res;
    142. }
    143. };
    144. istream& operator >> (istream& in, bigInt& x)
    145. {
    146. string s;
    147. x.a.clear();
    148. in>>s;
    149. for(int i=s.size()-1;i>=0;--i)
    150. x.a.push_back(s[i]-'0');
    151. return in;
    152. }
    153. ostream& operator<< (ostream& out, const bigInt& x)
    154. {
    155. for(int i=x.a.size()-1;i>=0;--i)
    156. out<<x.a[i];
    157. return out;
    158. }
    159. bigInt operator+ (const bigInt& a, const bigInt& b)
    160. {
    161. bigInt c;
    162. c=a;
    163. c+=b;
    164. return c;
    165. }
    166. bigInt operator* ( const bigInt& a, const bigInt& b)
    167. {
    168. bigInt c=a;
    169. c*=b;
    170. return c;
    171. }
    172. bigInt operator- (const bigInt& a, const bigInt b)
    173. {
    174. bigInt c;
    175. c=a;
    176. c-=b;
    177. return c;
    178. }
    179. bool operator < (const bigInt& a, const bigInt& b)
    180. {
    181. if(a.a.size()<b.a.size())
    182. return true;
    183. else
    184. {
    185. if(a.a.size()>b.a.size())
    186. return false;
    187. else
    188. {
    189. int i=0;
    190. while(a.a[i]==b.a[i])
    191. ++i;
    192. return a.a[i]<b.a[i];
    193. }
    194. }
    195. }
    196. int main()
    197. {
    198. vector<int> ans(5004,0);
    199. bigInt a(1);
    200. bigInt b(1);
    201. ans[1]=1;
    202. for(int i=3;i<=50000;++i)
    203. {
    204. bigInt c=a+b;
    205. if(c.a.size()>=5000)
    206. break;
    207. if( ans[c.a.size()]==0)
    208. ans[c.a.size()]=i;
    209. a=b;
    210. b=c;
    211. }
    212. int t;
    213. cin>>t;
    214. for(int k=1;k<=t;++k)
    215. {
    216. int n;
    217. cin>>n;
    218. cout<<ans[n]<<endl;
    219. }
    220.  
    221. }