algorithm_2024/src/P2822/P2822.cpp

37 lines
817 B
C++
Raw Normal View History

2024-10-08 05:41:59 +00:00
#include <iostream>
2024-10-08 06:55:42 +00:00
#include <algorithm>
2024-10-08 05:41:59 +00:00
2024-10-08 06:55:42 +00:00
using ull = unsigned long long;
2024-10-08 09:19:40 +00:00
#define NV(v)#v<<" : "<<(v)
2024-10-08 06:55:42 +00:00
static constexpr ull fact(const ull n)noexcept{
if(n==0)return 1;
ull ret {1};
for(ull i{2};i<=n;i++){
ret*=i;
}
return ret;
}
static constexpr ull C(const ull n, const ull m)noexcept{
return fact(n)/(fact(m)*fact(n-m));
}
2024-10-08 09:19:40 +00:00
static ull t, k, n, m, ans;
2024-10-08 05:41:59 +00:00
int main(){
2024-10-08 06:55:42 +00:00
// std::cout<<NV(fact(0))<<'\n'<<NV(fact(3))<<'\n';
std::iostream::sync_with_stdio(false), std::cin.tie(nullptr), std::cout.tie(nullptr);
std::cin>>t>>k;
for(ull i {0};i<t;i++){
std::cin>>n>>m;
2024-10-08 09:19:40 +00:00
ans = 0;
2024-10-08 06:55:42 +00:00
for(ull i {0};i<=n;i++){
for(ull j{0};j<=std::min(i,m);j++){
if(C(i,j)%k==0)ans++;
}
}
std::cout<<ans<<'\n';
}
2024-10-08 05:41:59 +00:00
}