sacgajcvs

Untitled

Oct 17th, 2020
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.34 KB | None | 0 0
  1. /*
  2. _____ _ _ _ _
  3. |_ _| |__ ___ / \ _ __ ___| |__ _ _| |
  4. | | | '_ \ / _ \ / _ \ | '_ \/ __| '_ \| | | | |
  5. | | | | | | __// ___ \| | | \__ \ | | | |_| | |
  6. |_| |_| |_|\___/_/ \_\_| |_|___/_| |_|\__,_|_|
  7.  
  8. */
  9. #include<bits/stdc++.h>
  10. #include <ext/pb_ds/assoc_container.hpp>
  11. #include <ext/pb_ds/tree_policy.hpp>
  12. #define ll long long
  13. #define pb push_back
  14. #define ppb pop_back
  15. #define endl '\n'
  16. #define mii map<ll,ll>
  17. #define msi map<string,ll>
  18. #define mis map<ll, string>
  19. #define rep(i,a,b) for(ll i=a;i<b;i++)
  20. #define repr(i,a,b) for(ll i=b-1;i>=a;i--)
  21. #define trav(a, x) for(auto& a : x)
  22. #define pii pair<ll,ll>
  23. #define vi vector<ll>
  24. #define vii vector<pair<ll, ll>>
  25. #define vs vector<string>
  26. #define all(a) (a).begin(),(a).end()
  27. #define F first
  28. #define S second
  29. #define sz(x) (ll)x.size()
  30. #define hell 1000000007
  31. #define lbnd lower_bound
  32. #define ubnd upper_bound
  33. #define max(a,b) (a>b?a:b)
  34. #define min(a,b) (a<b?a:b)
  35.  
  36. /* For Debugging */
  37. #define DEBUG cerr<<"\n>>>I'm Here<<<\n"<<endl;
  38. #define display(x) trav(a,x) cout<<a<<" ";cout<<endl;
  39. #define what_iss(x) cerr << #x << " = " << x << endl;
  40. #define what_is(x) cerr << #x << " = " << x << " ";
  41.  
  42. std::mt19937_64 rng(std::chrono::steady_clock::now().time_since_epoch().count());
  43. #define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
  44. #define TIME cerr << "\nTime elapsed: " << setprecision(5) <<1000.0 * clock() / CLOCKS_PER_SEC << "ms\n";
  45. #define DECIMAL(n) cout << fixed ; cout << setprecision(n);
  46. #define FAST ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
  47. using namespace __gnu_pbds;
  48. using namespace std;
  49. #define PI 3.141592653589793
  50. #define N 100005
  51.  
  52.  
  53. vector<vi> mul(vector<vi> p1, vector<vi> p2) {
  54. vector<vi> tmp(2,vi(2));
  55. rep(i,0,2) {
  56. rep(j,0,2) {
  57. tmp[i][j] = 0;
  58. rep(k,0,2) {
  59. tmp[i][j] += (p1[i][k] * p2[k][j]) % hell;
  60. }
  61. }
  62. }
  63. return tmp;
  64. }
  65.  
  66.  
  67. vector<vi> expo(vector<vi> base, ll exponent, ll mod) { //return base^exponent modulo modulus
  68. vector<vi> ans = {{1,0},{0,1}};
  69. while(exponent !=0 ) {
  70. if((exponent&1) == 1) {
  71. ans = mul(ans,base);
  72. // ans = ans*base ;
  73. // ans = ans%mod;
  74. }
  75. base = mul(base,base);
  76. // base = base*base;
  77. // base %= mod;
  78. exponent>>= 1;
  79. }
  80. return ans;
  81. }
  82.  
  83. ll expo(ll base, ll exponent, ll mod) { //return base^exponent modulo modulus
  84. ll ans = 1;
  85. while(exponent !=0 ) {
  86. if((exponent&1) == 1) {
  87. ans = ans*base ;
  88. ans = ans%mod;
  89. }
  90. base = base*base;
  91. base %= mod;
  92. exponent>>= 1;
  93. }
  94. return ans%mod;
  95. }
  96.  
  97. void solve()
  98. {
  99. ll n;
  100. cin >> n;
  101. ll num = (n + 1) / 2;
  102. ll ans;
  103. if(num == 1) {
  104. ans = 1;
  105. } else {
  106. vector<vi> tmp = {{3,1},{hell - 1,0}};
  107. // what_iss(num);
  108. tmp = expo(tmp,num - 1, hell);
  109. ans = tmp[0][0];
  110. }
  111. ll num2 = expo(2,n - 1,hell);
  112. // what_is(num2);
  113. // what_iss(ans);
  114. num2 = expo(num2,hell-2,hell);
  115. ans = (ans * num2) % hell;
  116. cout << ans << endl;
  117. return;
  118. }
  119. int main()
  120. {
  121. FAST
  122. int TESTS=1;
  123. cin>>TESTS;
  124. rep(i,0,TESTS)
  125. {
  126. // cout<<"Case #"<<i+1<<": ";
  127. solve();
  128. }
  129. // TIME
  130. return 0;
  131. }
Advertisement
Add Comment
Please, Sign In to add comment