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<