fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define ff first
  4. #define ss second
  5. #define mp make_pair
  6. #define all(v) v.begin(),v.end()
  7. #define int long long
  8. #define ll long long
  9. //#define M 1000000007
  10.  
  11. #define mii map<ll ,ll >
  12. #define msi map<string,ll >
  13. #define mis map<ll int, string>
  14. #define rep(a,b) for(ll i=a;i<b;i++)
  15. #define rep0(n) for(ll i=0;i<n;i++)
  16. #define repi(i,a,b) for(ll i=a;i<b;i++)
  17. #define pb push_back
  18. #define vi vector<ll>
  19. #define mp make_pair
  20. #define vs vector<string>
  21. #define ppb pop_back
  22. #define endl '\n'
  23. #define asdf ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
  24. #define r0 return 0;
  25. #define FORD(i, a, b) for (int i = (int) (a); i >= (int) (b); --i)
  26. #define FORE(it, c) for (__typeof((c).begin()) it = (c).begin(); it != (c).end(); ++it)
  27. #define inputoutput freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);
  28. #define input freopen("input.txt", "r", stdin);
  29. #define Set(a, s) 4(a, s, sizeof (a))
  30. #define FOR repi
  31. //#define float long double
  32. ll max(ll a, ll b) { return (a > b)? a : b;}
  33. int min(int a, int b) { return (a < b)? a : b;}
  34.  
  35.  
  36. void multiply(int a[2][2], int b[2][2])
  37. {
  38. // Creating an auxiliary matrix to store elements
  39. // of the multiplication matrix
  40. int mul[2][2];
  41. for (int i = 0; i < 2; i++)
  42. {
  43. for (int j = 0; j < 2; j++)
  44. {
  45. mul[i][j] = 0;
  46. for (int k = 0; k < 2; k++)
  47. mul[i][j] += a[i][k]*b[k][j];
  48. }
  49. }
  50.  
  51. // storing the muliplication resul in a[][]
  52. for (int i=0; i<2; i++)
  53. for (int j=0; j<2; j++)
  54. a[i][j] = mul[i][j]; // Updating our matrix
  55. }
  56.  
  57. // Function to compute F raise to power n-2.
  58. int power(int F[2][2], int n)
  59. {
  60. int M[2][2] = {{1,1},{1,0}};
  61.  
  62. // Multiply it with initial values i.e with
  63. // F(0) = 0, F(1) = 1, F(2) = 1
  64. if (n==1)
  65. return F[0][0] + F[0][1];//+F[1][0]+F[1][1];
  66.  
  67. power(F, n/2);
  68.  
  69. multiply(F, F);
  70.  
  71. if (n%2 != 0)
  72. multiply(F, M);
  73.  
  74. // Multiply it with initial values i.e with
  75. // F(0) = 0, F(1) = 1, F(2) = 1
  76. return F[0][0] + F[0][1];//+F[1][0]+F[1][1];
  77. }
  78.  
  79.  
  80.  
  81.  
  82.  
  83.  
  84.  
  85. int solve()
  86. {
  87. int n;
  88. cin>>n;
  89. int F[2][2] = {{1,1},{1,0}};
  90. //n--;
  91. //if(n==0) cout<<2;
  92. //else
  93. cout<<power(F,n);
  94.  
  95. }
  96. signed main()
  97. {
  98. asdf
  99. int t=1;
  100. cin>>t;
  101. while(t--)
  102. {
  103. solve();cout<<endl;
  104. }
  105.  
  106. }
Runtime error #stdin #stdout 0s 15232KB
stdin
Standard input is empty
stdout
Standard output is empty