fork download
  1. #include <bits/stdc++.h>
  2. //#include <ext/pb_ds/assoc_container.hpp>
  3.  
  4. //using namespace __gnu_pbds;
  5. using namespace std;
  6. //typedef tree<int,null_type,less_equal<int>,rb_tree_tag, tree_order_statistics_node_update> ordered_set;
  7. #define int long long
  8. #define mem(a,x) memset(a,x,sizeof(a))
  9. #define fast(s) s.reserve(2000); s.max_load_factor(0.5);
  10. #define F first
  11. #define S second
  12. #define pii pair <int, int>
  13. #define all(p) p.begin(), p.end()
  14. template<typename T> bool maximum(T &A, const T &B) {return A<B? A=B, true: false;}
  15. template<typename T> bool minimum(T &A, const T &B) {return A>B? A=B, true: false;}
  16. const int mod=998244353;
  17. const int base=2999;
  18. const int INF=1e9;
  19. const int N=1e5+5, M=10;
  20. int n, k, dp[100][101];
  21. void file()
  22. {
  23. #define task "diduduadi"
  24. if(fopen(task".inp","r"))
  25. {
  26. freopen(task".inp","r",stdin);
  27. freopen(task".out","w",stdout);
  28. }
  29. ios_base::sync_with_stdio(false);
  30. cin.tie(0);
  31. cout.tie(0);
  32. }
  33. struct Matrix
  34. {
  35. int n, m;
  36. vector<vector<int>> d;
  37. Matrix(int n=0, int m=0): n(n), m(m) {d.resize(n,vector<int>(m,0));}
  38. Matrix(const vector<vector<int>> &d): d(d)
  39. {
  40. n=(int)d.size();
  41. m=(n? (int)d[0].size(): 0);
  42. }
  43. Matrix operator* (const Matrix &a) const
  44. {
  45. int x=n, y=m, z=a.m;
  46. Matrix res(x,z);
  47. for(int i=0; i<x; ++i) for(int j=0; j<y; ++j) for(int k=0; k<z; ++k)
  48. {
  49. res.d[i][j]+=d[i][k]*a.d[k][j];
  50. res.d[i][j]%=mod;
  51. }
  52. return res;
  53. }
  54. Matrix operator^ (int k) const
  55. {
  56. Matrix res(n,n);
  57. for(int i=0; i<n; ++i) res.d[i][i]=1;
  58. Matrix tmp=*this;
  59. while(k)
  60. {
  61. if(k&1) res=res*tmp;
  62. tmp=tmp*tmp;
  63. k>>=1;
  64. }
  65. return res;
  66. }
  67. };
  68. vector<vector<int>> tmp;
  69. int pos(int i, int j)
  70. {
  71. return i*11+j;
  72. }
  73. void Solve()
  74. {
  75. cin>>n>>k;
  76. n-=k*(k-1)/2;
  77. if(n<k) return void(cout<<"0\n");
  78. dp[0][0]=1;
  79. for(int i=1; i<10; ++i)
  80. {
  81. for(int j=1; j<=10; ++j)
  82. {
  83. dp[i][j]+=dp[i-1][j-1];
  84. if(i>=j) (dp[i][j]+=dp[i-j][j]);
  85. }
  86. }
  87. if(n<10) return void(cout<<dp[n][k]<<"\n");
  88. tmp.resize(1,vector<int>(110));
  89. for(int i=0; i<10; ++i)
  90. for(int j=0; j<=10; ++j)
  91. tmp[0][pos(i,j)]=dp[i][j];
  92. Matrix mt(tmp);
  93. tmp.clear();
  94. tmp.resize(110,vector<int>(110,0));
  95. for(int i=0; i<10; ++i)
  96. {
  97. for(int j=1; j<=10; ++j)
  98. {
  99. if(i<9)
  100. {
  101. tmp[pos(i+1,j)][pos(i,j)]=1;
  102. continue;
  103. }
  104. tmp[pos(i,j-1)][pos(i,j)]=1;
  105. if(i-j+1>=0) tmp[pos(i-j+1,j)][pos(i,j)]=1;
  106. }
  107. }
  108. Matrix kk(tmp);
  109. kk=kk^(n-9);
  110. mt=mt*kk;
  111. cout<<mt.d[0][pos(9,k)]<<"\n";
  112. }
  113.  
  114. main()
  115. {
  116. file();
  117. Solve();
  118. return 0;
  119. }
  120.  
  121.  
Success #stdin #stdout 0.01s 5288KB
stdin
Standard input is empty
stdout
1