Now that CodeSprint 3 is over, I've been wondering how to solve this problem. We need to simply calculate nCr mod 142857 for large values of r and n (0<=n<=10^9 ; 0<=r<=n). I used a recursive method which goes through min(r, n-r) iterations to calculate the combination. Turns out this wasn't efficient enough. I've tried a few different methods, but they all seem to not be efficient enough. Any suggestions?
Calculated nCr mod m (n choose r) for large values of n (10^9)
5.8k Views Asked by AudioBubble At
1
There are 1 best solutions below
Related Questions in MODULO
- How to compute relative difference in a circular domain (weekday) in R
- Find nCr mod M where M is not prime
- C++: Quickest way to get integer within a range
- Modulo operator
- Trouble finding differential between two items in C++
- Finding modulo inverse if gcd is not 1
- Calculating the modulo of two intervals
- Visual Basic Random Number/Mod
- Newbie: Using $mod method during insert in mongodb
- Want to know how to find Modulo of a decimal number with 10^9 + 7?
- Universal hashing performs worse than modulo hashing, what is wrong?
- Modulo operation difference between Swift and Python
- how to restore number after modulo
- Modulo of high powers without using Math.BigInteger
- having trouble creating a modulo calculator with javascript
Related Questions in NCR
- MIPS Assembly - Trying to write a recursive program to calculate nCr (Combination)
- Function takes 0 positional arguments but 1 was given
- Strange outcome after passing array
- Generating nCr combinations of given set in java
- Calculated nCr mod m (n choose r) for large values of n (10^9)
- implementation of nCr and inverse factorial (MODm) for very large numbers
- How to search the MySQL entries shown as decimal numeric character reference(NCR) &#xxxxx?
- How to convert numeric character reference to Unicode in classic ASP?
- How to decode a NCR to unicode character in C++
- Batch script to hide Windows 10 Activation notifications
- Convert UTF-8 characters to NCR Iconv
- Recursive nCr Combinations in Java
- Detecting Overflow In nCr Function
- How can I fix this Combinations calculating(nCr) program?
- Converting from NCR to Unicode in R
Trending Questions
- UIImageView Frame Doesn't Reflect Constraints
- Is it possible to use adb commands to click on a view by finding its ID?
- How to create a new web character symbol recognizable by html/javascript?
- Why isn't my CSS3 animation smooth in Google Chrome (but very smooth on other browsers)?
- Heap Gives Page Fault
- Connect ffmpeg to Visual Studio 2008
- Both Object- and ValueAnimator jumps when Duration is set above API LvL 24
- How to avoid default initialization of objects in std::vector?
- second argument of the command line arguments in a format other than char** argv or char* argv[]
- How to improve efficiency of algorithm which generates next lexicographic permutation?
- Navigating to the another actvity app getting crash in android
- How to read the particular message format in android and store in sqlite database?
- Resetting inventory status after order is cancelled
- Efficiently compute powers of X in SSE/AVX
- Insert into an external database using ajax and php : POST 500 (Internal Server Error)
Popular Questions
- How do I undo the most recent local commits in Git?
- How can I remove a specific item from an array in JavaScript?
- How do I delete a Git branch locally and remotely?
- Find all files containing a specific text (string) on Linux?
- How do I revert a Git repository to a previous commit?
- How do I create an HTML button that acts like a link?
- How do I check out a remote Git branch?
- How do I force "git pull" to overwrite local files?
- How do I list all files of a directory?
- How to check whether a string contains a substring in JavaScript?
- How do I redirect to another webpage?
- How can I iterate over rows in a Pandas DataFrame?
- How do I convert a String to an int in Java?
- Does Python have a string 'contains' substring method?
- How do I check if a string contains a specific word?
For non-prime mod, factor it (142857 = 3^3 * 11 * 13 * 37) and compute C(n,k) mod p^q for each prime factor of the mod using the general Lucas theorem, and combine them using Chinese remainder theorem.
For example, C(234, 44) mod 142857 = 6084, then
The Chinese Remainder theorem involves finding x such that
The result is x = 6084.
Example
C(234, 44) mod 3^3
First convert n, k, and n-k to base p
n = 234_10 = 22200_3
k = 44_10 = 1122_3
r = n-k = 190_10 = 21001_3
Next find the number of carries
Now create the factorial function needed for general Lucas
Since q = 3, you will consider only three digits of the base p representation at a time
So
Now
Then
Now you have
This is a linear congruence and can be solved with
Hence C(234, 44) mod 3^3 = 9