Advertisement
Guest User

Untitled

a guest
Mar 22nd, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 8.08 KB | None | 0 0
  1. // ███▓▓▓▓▓▓▓▓▓╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬▓▓▓╬╬╬╬╬╬▓█
  2. // ███▓███████▓▓╬╬╬╬╬╬╬╬╬╬╬╬▓███▓▓▓▓█▓╬╬╬▓█
  3. // ███████▓█████▓▓╬╬╬╬╬╬╬╬▓███▓╬╬╬╬╬╬╬▓╬╬▓█
  4. // ████▓▓▓▓╬╬▓█████╬╬╬╬╬╬███▓╬╬╬╬╬╬╬╬╬╬╬╬╬█
  5. // ███▓▓▓▓╬╬╬╬╬╬▓██╬╬╬╬╬╬▓▓╬╬╬╬╬╬╬╬╬╬╬╬╬╬▓█
  6. // ████▓▓▓╬╬╬╬╬╬╬▓█▓╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬▓█
  7. // ███▓█▓███████▓▓███▓╬╬╬╬╬╬▓███████▓╬╬╬╬▓█
  8. // ████████████████▓█▓╬╬╬╬╬▓▓▓▓▓▓▓▓╬╬╬╬╬╬╬█
  9. // ███▓▓▓▓▓▓▓╬╬▓▓▓▓▓█▓╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬▓█
  10. // ████▓▓▓╬╬╬╬▓▓▓▓▓▓█▓╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬▓█
  11. // ███▓█▓▓▓▓▓▓▓▓▓▓▓▓▓▓╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬▓█
  12. // █████▓▓▓▓▓▓▓▓█▓▓▓█▓╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬▓█
  13. // █████▓▓▓▓▓▓▓██▓▓▓█▓╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██
  14. // █████▓▓▓▓▓████▓▓▓█▓╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██
  15. // ████▓█▓▓▓▓██▓▓▓▓██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██
  16. // ████▓▓███▓▓▓▓▓▓▓██▓╬╬╬╬╬╬╬╬╬╬╬╬█▓╬▓╬╬▓██
  17. // █████▓███▓▓▓▓▓▓▓▓████▓▓╬╬╬╬╬╬╬█▓╬╬╬╬╬▓██
  18. // █████▓▓█▓███▓▓▓████╬▓█▓▓╬╬╬▓▓█▓╬╬╬╬╬╬███
  19. // ██████▓██▓███████▓╬╬╬▓▓╬▓▓██▓╬╬╬╬╬╬╬▓███
  20. // ███████▓██▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓╬╬╬╬╬╬╬╬╬╬╬████
  21. // ███████▓▓██▓▓▓▓▓╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬▓████
  22. // ████████▓▓▓█████▓▓╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬▓█████
  23. // █████████▓▓▓█▓▓▓▓▓███▓╬╬╬╬╬╬╬╬╬╬╬▓██████
  24. // ██████████▓▓▓█▓▓▓╬▓██╬╬╬╬╬╬╬╬╬╬╬▓███████
  25. // ███████████▓▓█▓▓▓▓███▓╬╬╬╬╬╬╬╬╬▓████████
  26. // ██████████████▓▓▓███▓▓╬╬╬╬╬╬╬╬██████████
  27. // ███████████████▓▓▓██▓▓╬╬╬╬╬╬▓███████████
  28. #pragma GCC target("sse4,tune=native")
  29. #pragma GCC optimize("O3")
  30. #include <iostream>
  31. #include <vector>
  32. #include <string>
  33. #include <algorithm>
  34. #include <cstdio>
  35. #include <numeric>
  36. #include <cstring>
  37. #include <ctime>
  38. #include <cstdlib>
  39. #include <set>
  40. #include <map>
  41. #include <unordered_map>
  42. #include <unordered_set>
  43. #include <list>
  44. #include <cmath>
  45. #include <bitset>
  46. #include <cassert>
  47. #include <queue>
  48. #include <deque>
  49. #include <cassert>
  50. #include <iomanip>      
  51. #define pb push_back
  52. #define x first
  53. #define y second
  54. #define mp make_pair
  55. #define files(FILENAME) read(FILENAME); write(FILENAME)
  56. #define read(FILENAME) freopen((FILENAME + ".in").c_str(), "r", stdin)
  57. #define write(FILENAME) freopen((FILENAME + ".out").c_str(), "w", stdout)
  58. using namespace std;
  59.  
  60. template<typename T1, typename T2>inline void chkmin(T1 &x, T2 y) { if (x > y) x = y; }
  61. template<typename T1, typename T2>inline void chkmax(T1 &x, T2 y) { if (x < y) x = y; }
  62. template<typename T, typename U> inline ostream &operator<< (ostream &_out, const pair<T, U> &_p) { _out << _p.first << ' ' << _p.second; return _out; }
  63. template<typename T, typename U> inline istream &operator>> (istream &_in, pair<T, U> &_p) { _in >> _p.first >> _p.second; return _in; }
  64. template<typename T> inline ostream &operator<< (ostream &_out, const vector<T> &_v) { if (_v.empty()) { return _out; } _out << _v.front(); for (auto _it = ++_v.begin(); _it != _v.end(); ++_it) { _out << ' ' << *_it; } return _out; }
  65. template<typename T> inline istream &operator>> (istream &_in, vector<T> &_v) { for (auto &_i : _v) { _in >> _i; } return _in; }
  66. template<typename T> inline ostream &operator<< (ostream &_out, const set<T> &_s) { if (_s.empty()) { return _out; } _out << *_s.begin(); for (auto _it = ++_s.begin(); _it != _s.end(); ++_it) { _out << ' ' << *_it; } return _out; }
  67. template<typename T> inline ostream &operator<< (ostream &_out, const multiset<T> &_s) { if (_s.empty()) { return _out; } _out << *_s.begin(); for (auto _it = ++_s.begin(); _it != _s.end(); ++_it) { _out << ' ' << *_it; } return _out; }
  68. template<typename T> inline ostream &operator<< (ostream &_out, const unordered_set<T> &_s) { if (_s.empty()) { return _out; } _out << *_s.begin(); for (auto _it = ++_s.begin(); _it != _s.end(); ++_it) { _out << ' ' << *_it; } return _out; }
  69. template<typename T> inline ostream &operator<< (ostream &_out, const unordered_multiset<T> &_s) { if (_s.empty()) { return _out; } _out << *_s.begin(); for (auto _it = ++_s.begin(); _it != _s.end(); ++_it) { _out << ' ' << *_it; } return _out; }
  70. template<typename T, typename U> inline ostream &operator<< (ostream &_out, const map<T, U> &_m) { if (_m.empty()) { return _out; } _out << '(' << _m.begin()->first << ": " << _m.begin()->second << ')'; for (auto _it = ++_m.begin(); _it != _m.end(); ++_it) { _out << ", (" << _it->first << ": " << _it->second << ')'; } return _out; }
  71. template<typename T, typename U> inline ostream &operator<< (ostream &_out, const unordered_map<T, U> &_m) { if (_m.empty()) { return _out; } _out << '(' << _m.begin()->first << ": " << _m.begin()->second << ')'; for (auto _it = ++_m.begin(); _it != _m.end(); ++_it) { _out << ", (" << _it->first << ": " << _it->second << ')'; } return _out; }
  72.  
  73. typedef long double base;
  74. typedef pair<base, base> point;
  75.  
  76. const string FILENAME = "input";
  77.  
  78. int n, p;
  79.  
  80. void nsum(int &a, int b) {
  81.     a += b;
  82.     if (a >= p) a -= p;
  83. }
  84.  
  85. int sum(int a, int b) {
  86.     a += b;
  87.     return a >= p ? a - p : a;
  88. }
  89.  
  90. int mul(long long a, int b) {
  91.     return a * b % p;
  92. }
  93.  
  94. struct func {
  95.     int A, B, C, D;
  96.     func() {
  97.         A = B = C = D = 0;
  98.     }
  99.  
  100.     func(int x, int t) {
  101.         D = t;
  102.         C = mul(D, x);
  103.         B = mul(C, x);
  104.         A = mul(B, x);
  105.     }
  106.  
  107.     void add() {
  108.         A = sum(sum(A, D), mul(3, sum(B, C)));
  109.         B = sum(B, sum(D, sum(C, C)));
  110.         C = sum(C, D);
  111.     }
  112. };
  113.  
  114. func operator + (func a, func b) {
  115.     nsum(a.A, b.A);
  116.     nsum(a.B, b.B);
  117.     nsum(a.C, b.C);
  118.     nsum(a.D, b.D);
  119.     return a;
  120. }
  121.  
  122. const int MAXN = 1e5 + 1, SQRT = 340;
  123.  
  124. int dp1[MAXN][SQRT];
  125. int dp2[MAXN][SQRT];
  126. func suf[MAXN];
  127.  
  128. int main() {
  129.     ios::sync_with_stdio(0);
  130.     srand(time(0));
  131.     //read(FILENAME);
  132.     cin >> n >> p;
  133.     dp1[0][0] = 1;
  134.     for (int j = 1; j < SQRT; ++j) {
  135.         for (int i = j; i <= n; ++i) {
  136.             dp1[i][j] = sum(dp1[i - j][j], dp1[i - 1][j - 1]);
  137.         }
  138.     }
  139.     for (int j = 1; j <= SQRT; ++j) {
  140.         for (int i = j * (SQRT - 1); i <= n; ++i) {
  141.             dp2[i][j] = dp1[i - j * (SQRT - 1)][j];
  142.         }
  143.     }
  144.     for (int i = 1; i <= n; ++i) {
  145.         for (int j = 1; j <= SQRT; ++j) {
  146.             suf[i] = suf[i] + func(j, dp2[i][j]);
  147.         }
  148.     }
  149.     for (int j = SQRT; --j;) {
  150.         for (int i = j; i <= n; ++i) {
  151.             auto v = suf[i - j];
  152.             v.add();
  153.             suf[i] = suf[i] + v;
  154.             if (i == j) {
  155.                 suf[i].A++;
  156.                 suf[i].B++;
  157.                 suf[i].C++;
  158.                 suf[j].D++;
  159.             }
  160.         }
  161.     }
  162.     for (int i = 1; i <= n; ++i) {
  163.         cout << suf[i].A % p << '\n';
  164.     }
  165. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement