Advertisement
Guest User

Untitled

a guest
Apr 7th, 2020
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 5.42 KB | None | 0 0
  1. #pragma GCC optimize("O3", "unroll-loops")
  2.  
  3. #include <iostream>
  4. #include <iomanip>
  5. #include <vector>
  6. #include <algorithm>
  7. #include <cmath>
  8. #include <string>
  9. #include <map>
  10. #include <unordered_map>
  11. #include <set>
  12. #include <unordered_set>
  13. #include <bitset>
  14. #include <sstream>
  15. #include <deque>
  16. #include <queue>
  17. #include <complex>
  18. #include <random>
  19. #include <cassert>
  20. #include <chrono>
  21.  
  22. using namespace std;
  23.  
  24. #define FAST ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
  25. #define FIXED cout << fixed << setprecision(12)
  26. #define ll long long
  27. #define ld long double
  28. #define pii pair<int, int>
  29. #define pll pair<ll, ll>
  30. #define graph vector<vector<int>>
  31. #define pb push_back
  32. #define pf push_front
  33. #define popb pop_back
  34. #define popf pop_front
  35. #define f first
  36. #define s second
  37. #define hashmap unordered_map
  38. #define hashset unordered_set
  39. #define eps 1e-9
  40. #define mod 1000000007
  41. #define inf 3000000000000000007ll
  42. #define sz(a) signed(a.size())
  43. #define all(a) a.begin(), a.end()
  44. #define rall(a) a.rbegin(), a.rend()
  45.  
  46. #ifdef DEBUG
  47.     mt19937 gen(857204);
  48. #else
  49.     mt19937 gen(chrono::high_resolution_clock::now().time_since_epoch().count());
  50. #endif
  51.  
  52. template<class T, class U> inline void checkmin(T &x, U y) { if (y < x) x = y; }
  53. template<class T, class U> inline void checkmax(T &x, U y) { if (y > x) x = y; }
  54. template<class T, class U> inline bool ifmax(T &x, U y) { if (y > x) return x = y, true; return false; }
  55. template<class T, class U> inline bool ifmin(T &x, U y) { if (y < x) return x = y, true; return false; }
  56. template<class T> inline void sort(T &a) { sort(all(a)); }
  57. template<class T> inline void rsort(T &a) { sort(rall(a)); }
  58. template<class T> inline void reverse(T &a) { reverse(all(a)); }
  59. template<class T, class U> inline istream& operator>>(istream& str, pair<T, U> &p) { return str >> p.f >> p.s; }
  60. template<class T> inline istream& operator>>(istream& str, vector<T> &a) { for (auto &i : a) str >> i; return str; }
  61. template<class T> inline T sorted(T a) { sort(a); return a; }
  62.  
  63. struct zet {
  64.     int val;
  65.     explicit operator int() const { return val; }
  66.     zet(ll x = 0) { val = (x >= -mod && x < mod ? x : x % mod); if (val < 0) val += mod; }
  67.     zet(ll a, ll b) { *this += a; *this /= b; }
  68.  
  69.     zet& operator+=(zet const &b) { val += b.val; if (val >= mod) val -= mod; return *this; }
  70.     zet& operator-=(zet const &b) { val -= b.val; if (val < 0) val += mod; return *this; }
  71.     zet& operator*=(zet const &b) { val = (val * (ll)b.val) % mod; return *this; }
  72.  
  73.     friend zet mypow(zet a, ll n) {
  74.         zet res = 1;
  75.         while (n) { if (n & 1) res *= a; a *= a; n >>= 1; }
  76.         return res;
  77.     }
  78.     friend zet inv(zet a) { return mypow(a, mod - 2); }
  79.     zet& operator/=(zet const& b) { return *this *= inv(b); }
  80.     friend zet operator+(zet a, const zet &b) { return a += b; }
  81.     friend zet operator-(zet a, const zet &b) { return a -= b; }
  82.     friend zet operator-(zet a) { return 0 - a; }
  83.     friend zet operator*(zet a, const zet &b) { return a *= b; }
  84.     friend zet operator/(zet a, const zet &b) { return a /= b; }
  85.     friend istream& operator>>(istream& stream, zet &a) { return stream >> a.val; }
  86.     friend ostream& operator<<(ostream& stream, const zet &a) { return stream << a.val; }
  87.     friend bool operator==(zet const &a, zet const &b) { return a.val == b.val; }
  88.     friend bool operator!=(zet const &a, zet const &b) { return a.val != b.val; }
  89.     friend bool operator<(zet const &a, zet const &b) { return a.val < b.val; }
  90. };
  91.  
  92. vector<vector<zet>> operator*(vector<vector<zet>> a, vector<vector<zet>> b) {
  93.     assert(sz(a[0]) == sz(b));
  94.     vector<vector<zet>> ans(sz(a), vector<zet>(sz(b[0])));
  95.     for (int i = 0; i < sz(a); ++i)
  96.         for (int j = 0; j < sz(b[0]); ++j)
  97.             for (int r = 0; r < sz(a[0]); ++r)
  98.                 ans[i][j] += a[i][r] * b[r][j];
  99.     return ans;
  100. }
  101.  
  102. vector<vector<zet>> mpow(vector<vector<zet>> a, ll n) {
  103.     assert(sz(a) == sz(a[0]));
  104.     vector<vector<zet>> ans(sz(a), vector<zet>(sz(a[0])));
  105.     for (int i = 0; i < sz(a); ++i) ans[i][i] = 1;
  106.     while (n > 0) {
  107.         if (n & 1) ans = ans * a;
  108.         a = a * a;
  109.         n >>= 1;
  110.     }
  111.     return ans;
  112. }
  113.  
  114. signed main() {
  115.     FAST; FIXED;
  116.     ll n;
  117.     cin >> n;
  118.     if (n == 1) {
  119.         cout << 1;
  120.         return 0;
  121.     }
  122.     vector<vector<zet>> start = {
  123.         {0, 0, 1},
  124.         {0, 0, 0},
  125.         {0, 0, 0}
  126.     };
  127.     for (int a = 0; a <= 10; ++a)
  128.         for (int b = 0; b <= 10; ++b)
  129.             for (int c = 0; c <= 10; ++c) {
  130.                 vector<vector<zet>> mul = {
  131.                     {0, 0, a},
  132.                     {1, 0, b},
  133.                     {0, 1, c}
  134.                 };
  135.                 start = start * mpow(mul, n - 1);
  136.                 for (int d = 0; d <= 10; ++d)
  137.                     for (int t = 0; t <= 10; ++t)
  138.                         for (int k = 0; k <= 10; ++k) {
  139.                         zet ans = 0;
  140.                         vector<zet> add = {0, d, t, k};
  141.                         for (int cnt = 1; cnt <= 3; ++cnt)
  142.                             ans += start[0][3 - cnt] * add[cnt];
  143.                         if (ans == 729888649) {
  144.                             cout << a << ' ' << b << ' ' << c << '\n';
  145.                             return 0;
  146.                         }
  147.                     }
  148.             }
  149.     #ifdef DEBUG
  150.         cerr << "Runtime is: " << clock() * 1.0 / CLOCKS_PER_SEC << endl;
  151.     #endif
  152.     return 0;
  153. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement