0

Does anybody know a fast algorithm for calculating a large catalan number modulo a prime (which is 1.000.000.007) with an input value of about 500.000

Already spent quite some time on it but I wasn't able to modify the normal formular to work with that high numbers and the dynamic algorithm takes too long.

I'd be very grateful for any help :)

Guy Coder
  • 24,501
  • 8
  • 71
  • 136

1 Answers1

0

Using the open source and python-based program sage it takes 11 seconds on my old double core 2.80Ghz laptop to compute the residue class of the Catalan number you asked for:

huisman@thom:~$ sage
┌────────────────────────────────────────────────────────────────────┐
│ SageMath Version 6.10, Release Date: 2015-12-18                    │
│ Type "notebook()" for the browser-based notebook interface.        │
│ Type "help()" for help.                                            │
└────────────────────────────────────────────────────────────────────┘
sage: time catalan_number(5*10^5).mod(10^9+7)
CPU times: user 11.3 s, sys: 0 ns, total: 11.3 s
Wall time: 11.3 s
213941567

By inspecting the code you can get an idea how to do it so fast.