Почему nCr большого числа дает неправильный ответ - PullRequest
0 голосов
/ 29 апреля 2020

Я пытаюсь решить вопрос https://practice.geeksforgeeks.org/problems/nth-catalan-number/0, используя подход, где k = n -r

for(int i=0; i<k; i++){
                        res = res * (n - i);
                        res = (res/(i+1))%1000000007;
                    }
for n and r
but it get failed in the input n=778  and r = 116
but using the dynamic programming (by using two dimensional array) method it give the right answer
what are the reason of failure of first approach and success of second (dynamic programming) approach

1 Ответ

0 голосов
/ 29 апреля 2020
(a / b) mod p = ((a mod p) * (b^(-1) mod p)) mod p

Вы должны использовать модульное деление.

Посмотрите на этот вопрос Ссылка

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...