Advertisement
Guest User

Untitled

a guest
Apr 7th, 2020
187
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.60 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. #include <random>
  3.  
  4. using namespace std;
  5.  
  6. typedef unsigned long long ull;
  7. typedef long long ll;
  8. typedef double ld;
  9. #define int ll
  10. typedef vector<char> vc;
  11. typedef vector<vc> vvc;
  12. typedef vector<vvc> vvvc;
  13. typedef pair<int, int> pii;
  14. typedef pair<pii, pii> piii;
  15. typedef pair<ll, ll> pll;
  16. typedef vector<int> vi;
  17. typedef vector<pii> vpi;
  18. typedef vector< vi > vvi;
  19. typedef vector< vvi > vvvi;
  20. typedef vector<short> vs;
  21. typedef vector<vs> vvs;
  22. typedef vector<vvs> vvvs;
  23. typedef vector<ll> vl;
  24. typedef vector<vl> vvl;
  25. typedef vector<vvl> vvvl;
  26. typedef vector<ld> vld;
  27. typedef vector<vld> vvld;
  28. typedef vector<vvld> vvvld;
  29. typedef vector<string> vst;
  30. typedef vector<vst> vvst;
  31. typedef pair<ld, ld> pld;
  32.  
  33. #define inmin(a, b) a = min(a, (b))
  34. #define inmax(a, b) a = max(a, (b))
  35. #define ALL(a) a.begin(),a.end()
  36. #define RALL(a) a.rbegin(),a.rend()
  37. #define sqr(x) ((x) * (x))
  38. #define fori(i, n) for(int i = 0; i < int(n); ++i)
  39. #define SZ(a) ((int)((a).size()))
  40. #define triple(T) tuple<T, T, T>
  41. #define quad(T) tuple<T, T, T, T>
  42. #define watch(x) cerr << (#x) << " = " << (x) << endl;
  43.  
  44. #ifdef RUS_HOME
  45. #define cerr cout
  46. #else
  47. #define cerr if (false) cerr
  48. #endif
  49.  
  50. const double PI = 2 * acos(0.0);
  51. #define rand shittttty_shit
  52. mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
  53. mt19937_64 rng_64(chrono::steady_clock::now().time_since_epoch().count());
  54.  
  55. const string DIGITS = "0123456789";
  56. const string ALPH = "abcdefghijklmnopqrstuvwxyz";
  57.  
  58.  
  59. template <class T0, class T1>
  60. inline ostream & operator << (ostream &out, pair<T0, T1> &a) {
  61.     return out << "{" << a.first << ", " << a.second << "}";
  62. }
  63.  
  64. template <class T0, class T1>
  65. inline istream & operator >> (istream &in, pair<T0, T1> &a) {
  66.     return in >> a.first >> a.second;
  67. }
  68.  
  69. template <class T0, class T1, class T2>
  70. inline ostream & operator << (ostream &out, tuple<T0, T1, T2> &a) {
  71.     return out << "{" << get<0>(a) << ", " << get<1>(a) << ", " << get<2>(a) << "}";
  72. }
  73.  
  74. template <class T0, class T1, class T2, class T3>
  75. inline ostream & operator << (ostream &out, tuple<T0, T1, T2, T3> &a) {
  76.     return out << "{" << get<0>(a) << ", " << get<1>(a) << ", " << get<2>(a) << ", " <<  get<3>(a) << "}";
  77. }
  78.  
  79. template<class T>
  80. inline ostream & operator << (ostream &out, vector<T> &a) {
  81.     out << "[";
  82.     fori (i, a.size())
  83.         out << a[i] << vector<string>{", ", "]  "}[i + 1 == a.size()];
  84.     return out;
  85. }
  86.  
  87.  
  88. void smain();
  89.  
  90.  
  91.  
  92. signed main() {
  93.     ios::sync_with_stdio(0);
  94.     cin.tie(0); cout.tie(0);
  95. #ifdef RUS_HOME
  96.     freopen("input", "r", stdin);
  97.     clock_t start = clock();
  98. #endif
  99.     cout << setprecision(12) << fixed;
  100.     smain();
  101. #ifdef RUS_HOME
  102.     cout << "\n\n\n\nTOTAL EXECUTION TIME: " << float( clock () - start ) /  CLOCKS_PER_SEC << endl;
  103. #endif
  104.     return 0;
  105. }
  106.  
  107. const int N=2e3+100,MOD=1e9+7;
  108.  
  109. vvi mult(vvi a, vvi b){
  110.     int n=SZ(a);
  111.     int m=SZ(b[0]);
  112.     int k=SZ(b);
  113.     vvi c(n,vi(m));
  114.     for(int i=0;i<n;i++){
  115.         for(int j=0;j<m;j++){
  116.             for(int l=0;l<k;l++){
  117.                 c[i][j]=(c[i][j]+a[i][l]*b[l][j])%MOD;
  118.             }
  119.         }
  120.     }
  121.     return c;
  122. }
  123.  
  124. vvi pow(vvi a, int n){
  125.     vvi c={{1,0,0},{0,1,0},{0,0,1}};
  126.     while(n){
  127.         if(n&1)
  128.             c=mult(c,a);
  129.         a=mult(a,a);
  130.         n>>=1;
  131.     }
  132.     return c;
  133. }
  134.  
  135. vvi kek={{1,2,1},{1,0,0},{0,1,0}};
  136.  
  137. void smain() {
  138.     int n;
  139.     cin>>n;
  140.     if(n==1){
  141.         cout<<1;
  142.         return;
  143.     }
  144.     vvi d={{1,0,0}};
  145.     vvi a=mult(d,pow(kek,n+1));
  146.     //vvi b=mult(d,pow(kek,n));
  147.     //vvi c=mult(d,pow(kek,n-2));
  148.     cout<<(a[0][0])%MOD;
  149.  
  150. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement