Thread: help with combinations !!!!

  1. #1
    Registered User
    Join Date
    Oct 2009
    Posts
    11

    help with combinations !!!!

    hi frndz....

    i was wondering that given
    1<n<1000000 &
    1<r<1000000

    how do i efficiently find nCr (combination) for any given values of n & r.

    please help with an efficient algorithm...

  2. #2
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Forgive my ignorance of mathematics but it would seem to me this does not any algorithm.

    Code:
    {r,n}
    [aside:] For some silly reason cboard's vBulletin believes everything in braces is code...unless you are new and want to paste a few hundred lines
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  3. #3
    and the hat of copycat stevesmithx's Avatar
    Join Date
    Sep 2007
    Posts
    587
    As nCr would be factorial(n)/(factorial(r)*factorial(n-r)) I guess it boils down to finding the factorial efficiently.
    If an approximate solution would be okay, then go for http://en.wikipedia.org/wiki/Stirling%27s_approximation
    Not everything that can be counted counts, and not everything that counts can be counted
    - Albert Einstein.


    No programming language is perfect. There is not even a single best language; there are only languages well suited or perhaps poorly suited for particular purposes.
    - Herbert Mayer

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. possible eight-letter combinations
    By abuna in forum C Programming
    Replies: 1
    Last Post: 09-07-2005, 05:52 AM
  2. Combinations
    By Cmuppet in forum C Programming
    Replies: 6
    Last Post: 10-19-2004, 07:39 AM
  3. Grabbing Ctrl and Alt key combinations
    By scorpio_IITR in forum Linux Programming
    Replies: 0
    Last Post: 04-12-2004, 03:01 AM
  4. Combinations, lotto, 6/49
    By Robert in forum C++ Programming
    Replies: 8
    Last Post: 12-06-2002, 07:27 PM
  5. Combinations
    By GaPe in forum C Programming
    Replies: 16
    Last Post: 01-09-2002, 05:38 AM