update
This commit is contained in:
parent
49bdd569a7
commit
84d0f094d8
34
src/P2822/P2822_prefix.cpp
Normal file
34
src/P2822/P2822_prefix.cpp
Normal file
@ -0,0 +1,34 @@
|
||||
#include <iostream>
|
||||
#include <algorithm>
|
||||
|
||||
using ull = unsigned long long;
|
||||
|
||||
static constexpr size_t max_n {(size_t)2e3+5};
|
||||
|
||||
ull k, c[max_n][max_n], prefix[max_n][max_n], t, n, m;
|
||||
|
||||
static void init(){
|
||||
c[0][0] = c[1][0] = c[1][1] = 1;
|
||||
for(ull i {2};i<max_n;i++){
|
||||
c[i][0]=1;
|
||||
for(ull j{1};j<max_n;j++){
|
||||
c[i][j] = (c[i-1][j-1] + c[i-1][j])%k;
|
||||
}
|
||||
}
|
||||
for(ull i {2};i<max_n;i++){
|
||||
for(ull j{1};j<=i;j++){
|
||||
prefix[i][j] = prefix[i-1][j]+prefix[i][j-1]-prefix[i-1][j-1] + (c[i][j]==0?1:0);
|
||||
}
|
||||
prefix[i][i+1] = prefix[i][i];
|
||||
}
|
||||
}
|
||||
|
||||
int main(){
|
||||
std::cin>>t>>k;
|
||||
init();
|
||||
for(ull i {0};i<t;i++){
|
||||
std::cin>>n>>m;
|
||||
m = std::min(m,n);
|
||||
std::cout<<(prefix[n][m])<<'\n';
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user