This commit is contained in:
Zengtudor 2024-10-08 18:34:38 +08:00
parent 09afebc7df
commit 4195226207

View File

@ -1,24 +1,29 @@
#include <iostream> #include <iostream>
#include <algorithm> #include <algorithm>
#include <map>
using ull = unsigned long long; using ull = unsigned long long;
#define NV(v)#v<<" : "<<(v) #define NV(v)#v<<" : "<<(v)
static constexpr ull fact(const ull n)noexcept{ static ull t, k, n, m, ans;
static std::map<ull,ull> fact_map;
static ull fact(const ull n)noexcept{
if(n==0)return 1; if(n==0)return 1;
const auto it = fact_map.find(n);
if(it != fact_map.end())return (*it).second;
ull ret {1}; ull ret {1};
for(ull i{2};i<=n;i++){ for(ull i{2};i<=n;i++){
ret*=i; ret=(ret*i)%k;
} }
fact_map.insert({n,ret});
return ret; return ret;
} }
static constexpr ull C(const ull n, const ull m)noexcept{ static ull C(const ull n, const ull m)noexcept{
return fact(n)/(fact(m)*fact(n-m)); return fact(n)/(fact(m)*fact(n-m)%k);
} }
static ull t, k, n, m, ans;
int main(){ int main(){
// std::cout<<NV(fact(0))<<'\n'<<NV(fact(3))<<'\n'; // 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::iostream::sync_with_stdio(false), std::cin.tie(nullptr), std::cout.tie(nullptr);