Guest User

Untitled

a guest
Oct 13th, 2015
356
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 8.38 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. #define ARG4(_1,_2,_3,_4,...) _4
  5.  
  6. #define forn3(i,l,r) for (int i = int(l); i < int(r); ++i)
  7. #define forn2(i,n) forn3 (i, 0, n)
  8. #define forn(...) ARG4(__VA_ARGS__, forn3, forn2) (__VA_ARGS__)
  9.  
  10. #define ford3(i,l,r) for (int i = int(r) - 1; i >= int(l); --i)
  11. #define ford2(i,n) ford3 (i, 0, n)
  12. #define ford(...) ARG4(__VA_ARGS__, ford3, ford2) (__VA_ARGS__)
  13.  
  14. #define ve vector
  15. #define pa pair
  16. #define tu tuple
  17. #define mp make_pair
  18. #define mt make_tuple
  19. #define pb push_back
  20. #define fs first
  21. #define sc second
  22. #define all(a) (a).begin(), (a).end()
  23. #define sz(a) ((int)(a).size())
  24.  
  25. typedef long double ld;
  26. typedef int64_t ll;
  27. typedef uint64_t ull;
  28. typedef uint32_t ui;
  29. typedef uint16_t us;
  30. typedef uint8_t uc;
  31. typedef pa<int, int> pii;                                                                                                                                                                            
  32. typedef pa<int, ll> pil;                                                                                                                                                                            
  33. typedef pa<ll, int> pli;                                                                                                                                                                            
  34. typedef pa<ll, ll> pll;                                                                                                                                                                              
  35. typedef ve<int> vi;                                                                                                                                                                                  
  36.                                                                                                                                                                                                      
  37. const ld pi = 3.1415926535897932384626433832795l;                                                                                                                                                    
  38.                                                                                                                                                                                                      
  39. template<typename T> inline auto sqr (T x) -> decltype(x * x) {return x * x;}                                                                                                                        
  40. template<typename T1, typename T2> inline bool umx (T1& a, T2 b) {if (a < b) {a = b; return 1;} return 0;}                                                                                          
  41. template<typename T1, typename T2> inline bool umn (T1& a, T2 b) {if (b < a) {a = b; return 1;} return 0;}                                                                                          
  42.                                                                                                                                                                                                      
  43. struct Input {                                                                                                                                                                                      
  44.         bool read () {                                                                                                                                                                              
  45.         }                                                                                                                                                                                            
  46.                                                                                                                                                                                                      
  47.         void init (const Input &input) {                                                                                                                                                            
  48.                 *this = input;                                                                                                                                                                      
  49.         }                                                                                                                                                                                            
  50. };
  51.  
  52. struct Data: Input {
  53.         void write () {
  54.         }
  55. };
  56.  
  57. struct Solution: Data {
  58.  
  59.         static const int MOD = 1000000007;
  60.         static const int N = 60;
  61.  
  62.     int get_pow(int x, int st) {
  63.         int res = 1;
  64.         while (st) {
  65.             if (st & 1) {
  66.                 res = 1ll * res * x % MOD;
  67.             }
  68.             st /= 2;
  69.             x = 1ll * x * x % MOD;
  70.         }
  71.         return res;
  72.     }
  73.  
  74.         int rev(int x) {
  75.         return get_pow(x, MOD - 2);
  76.     }
  77.  
  78.         int a[N + 1], b[N + 1], c[N + 1], d[N + 1][N + 1], cnt[N + 1];
  79.     int part[N + 2], pbrt[N + 2];
  80.     int pcnt;
  81.     int fact[N + 1], rfact[N + 1];
  82.     int gcd[N + 1][N + 1];
  83.     int pow2[N * N];
  84.  
  85.         void calc_add(int coeff, int st) {
  86.         cnt[n]++;
  87.         a[n] = (a[n] + 1ll * coeff * pow2[st]) % MOD;
  88.         if (part[0] != n) {
  89.             int sub = 1;
  90.             forn(i, pcnt) {
  91.                 sub = 1ll * sub * big[part[i]][pbrt[i]] % MOD;
  92.             }
  93.             a[n] = (a[n] + MOD - sub) % MOD;
  94.         }
  95.         }
  96.  
  97.     int big_binom(int n, int k) {
  98.         n = (n + k - 1) % MOD;
  99.         int res = rfact[k];
  100.         forn(i, k) {
  101.             res = 1ll * res * (n + MOD - i) % MOD;
  102.         }
  103.         return res;
  104.     }
  105.    
  106.     int binom(int n, int k) {
  107.         return 1ll * fact[n] * rfact[k] % MOD * rfact[n - k] % MOD;
  108.     }
  109.  
  110.     int mult[N + 1][N + 1];
  111.     int big[N + 1][N + 1];
  112.  
  113.     int left;
  114.     int pr;
  115.     int n;
  116.  
  117.         void rec(int coeff, int st = 0, int add = 0) {
  118.         if (!left) {
  119.             calc_add(coeff, st + add);
  120.             return;
  121.         }
  122.         if (!pr) {
  123.             return;
  124.         }
  125.         --pr;
  126.         rec(coeff, st, add);
  127.         ++pr;
  128.         int old_pcnt = pcnt;
  129.         part[pcnt++] = pr;
  130.         int add_gcd = pr / 2;
  131.         forn(i, old_pcnt) {
  132.             add_gcd += pbrt[i] * gcd[part[i]][pr];
  133.         }
  134.         if (pr & 1) add = 1;
  135.         for (int cnt = 1; cnt * pr <= left; ++cnt) {
  136.             int ncoeff = 1ll * coeff * binom(left, cnt * pr) % MOD;
  137.             ncoeff = 1ll * ncoeff * mult[cnt][pr] % MOD;
  138.             pbrt[old_pcnt] = cnt;
  139.             st += add_gcd + (cnt - 1) * pr;
  140.             left -= cnt * pr;
  141.             --pr;
  142.             rec(ncoeff, st, add);
  143.             ++pr;
  144.             left += cnt * pr;
  145.         }
  146.         pcnt = old_pcnt;
  147.         }
  148.  
  149.         Solution() {
  150.                 memset(a, 0, sizeof(a));
  151.                 memset(b, 0, sizeof(b));
  152.                 memset(c, 0, sizeof(c));
  153.                 memset(d, 0, sizeof(d));
  154.         memset(cnt, 0, sizeof(cnt));
  155.         pcnt = 0;
  156.         fact[0] = rfact[0] = 1;
  157.         forn (i, 1, N + 1) {
  158.             fact[i] = 1ll * fact[i - 1] * i % MOD;
  159.             rfact[i] = rev(fact[i]);
  160.         }
  161.         forn (len, 1, N + 1) {
  162.             mult[0][len] = 1;
  163.             for (int cnt = 1; cnt * len <= N; ++cnt) {
  164.                 mult[cnt][len] = 1ll * mult[cnt - 1][len] * fact[cnt * len - 1] % MOD;
  165.                 mult[cnt][len] = 1ll * mult[cnt][len] * rfact[(cnt - 1) * len] % MOD;
  166.             }
  167.         }
  168.         forn(i, 1, N + 1) {
  169.             forn(j, 1, N + 1) {
  170.                 gcd[i][j] = __gcd(i, j);
  171.             }
  172.         }
  173.         pow2[0] = 1;
  174.         forn(i, 1, N * N) {
  175.             pow2[i] = (pow2[i - 1] * 2) % MOD;
  176.         }
  177.                 forn (dn, 1, N + 1) {
  178.             left = pr = n = dn;
  179.                         rec(rfact[n]);
  180.             forn(i, N + 1) {
  181.                 big[n][i] = big_binom(a[n], i);
  182.             }
  183.         }
  184.         c[0] = MOD - 1;
  185.         forn(i, 1, N + 1) {
  186.             c[i] = (c[i - 1] + a[i]) % MOD;
  187.         }
  188.         cout << "static const int c[] = {0";
  189.         forn(i, 1, N + 1) {
  190.             cout << ", " << c[i];
  191.         }
  192.         cout << "};" << endl;
  193.         }
  194.  
  195.         void solve () {
  196.         }
  197.  
  198.         void clear () {
  199.         }
  200. };
  201.  
  202. Solution sol;
  203.  
  204. int main () {
  205.         return 0;
  206. }
Advertisement
Add Comment
Please, Sign In to add comment