找到大n和k模m的二项式系数

编程入门 行业动态 更新时间:2024-10-13 02:19:02
本文介绍了找到大n和k模m的二项式系数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我想使用以下约束来计算nCk mod m:

n <= 10 ^ 18

k <= 10 ^ 5

m = 10 ^ 9 + 7

/ p>

计算二项系数( nCk)但是这里m的值是1009.因此,使用Lucas定理,我们只需要计算aCb的1009 * 1009个不同的值,其中a,b

如何使用上述约束。 我不能使用给定的约束来创建O(m * k)空间复杂度的数组。

帮助!

解决方案

只需使用

(n,k)= n ! / k! /(n-k)! = n *(n-1)* ... *(n-k + 1)/ [k *(k-1)* ... * 1]

因此你实际上只有 2 * k = 2 * 10 ^ 5 对于数字的倒数,您可以使用 kfx 的建议,因为您的 m 是素数。

I want to compute nCk mod m with following constraints:

n<=10^18

k<=10^5

m=10^9+7

I have read this article:

Calculating Binomial Coefficient (nCk) for large n & k

But here value of m is 1009. Hence using Lucas theorem, we need only to calculate 1009*1009 different values of aCb where a,b<=1009

How to do it with above constraints. I cannot make a array of O(m*k) space complexity with given constraints.

Help!

解决方案

Just use the fact that

(n, k) = n! / k! / (n - k)! = n*(n-1)*...*(n-k+1)/[k*(k-1)*...*1]

so you actually have just 2*k=2*10^5 factors. For the inverse of a number you can use suggestion of kfx since your m is prime.

更多推荐

找到大n和k模m的二项式系数

本文发布于:2023-11-29 14:13:28,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1646618.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:系数   二项式

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!