From 4195226207122d0e8689ad28d926f99b2883619d Mon Sep 17 00:00:00 2001 From: Zengtudor Date: Tue, 8 Oct 2024 18:34:38 +0800 Subject: [PATCH] update --- src/P2822/P2822.cpp | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/P2822/P2822.cpp b/src/P2822/P2822.cpp index 2a2f56a..d452170 100644 --- a/src/P2822/P2822.cpp +++ b/src/P2822/P2822.cpp @@ -1,24 +1,29 @@ #include #include +#include using ull = unsigned long long; #define NV(v)#v<<" : "<<(v) -static constexpr ull fact(const ull n)noexcept{ +static ull t, k, n, m, ans; +static std::map fact_map; + +static ull fact(const ull n)noexcept{ if(n==0)return 1; + const auto it = fact_map.find(n); + if(it != fact_map.end())return (*it).second; ull ret {1}; for(ull i{2};i<=n;i++){ - ret*=i; + ret=(ret*i)%k; } + fact_map.insert({n,ret}); return ret; } -static constexpr ull C(const ull n, const ull m)noexcept{ - return fact(n)/(fact(m)*fact(n-m)); +static ull C(const ull n, const ull m)noexcept{ + return fact(n)/(fact(m)*fact(n-m)%k); } -static ull t, k, n, m, ans; - int main(){ // std::cout<