From 49bdd569a737d5a2acfd3b3e39780afa4dd739a9 Mon Sep 17 00:00:00 2001 From: Zengtudor Date: Tue, 8 Oct 2024 19:02:13 +0800 Subject: [PATCH] update --- src/P2822/P2822.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/P2822/P2822.cpp b/src/P2822/P2822.cpp index 9fe8d80..51ae042 100644 --- a/src/P2822/P2822.cpp +++ b/src/P2822/P2822.cpp @@ -7,6 +7,7 @@ using ull = unsigned long long; static ull t, k, n, m, ans; static std::map fact_map; +static std::map,ull> C_map; static ull fact(const ull n)noexcept{ if(n==0)return 1; @@ -14,14 +15,18 @@ static ull fact(const ull n)noexcept{ if(it != fact_map.end())return (*it).second; ull ret {1}; for(ull i{2};i<=n;i++){ - ret=(ret%k*i%k); + ret*=i; } fact_map.insert({n,ret}); return ret; } static ull C(const ull n, const ull m)noexcept{ - return fact(n)/(fact(m)*fact(n-m)%k); + const auto it = C_map.find({n,m}); + if(it!=C_map.end())return (*it).second; + const ull ret = (fact(n))/(fact(m)*fact(n-m)); + C_map.insert({{n,m},ret}); + return ret; } int main(){