Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8433489
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T06:23:59+00:00 2026-06-10T06:23:59+00:00

I am solving a programming problem which is stuck at calculating nCr efficiently and

  • 0

I am solving a programming problem which is stuck at calculating nCr efficiently and at the same time avoiding overflows. I have made the following trivial simplification but am just curious about if there are any more sophisticated simplifications available out there.

(n)!/(n-k)!*k! = n*(n-1)*.....*(max(n-k+1, k))/(min(n-k, k-1))

Can there be any more simplification possible considering different cases for k as even or odd, just suggesting a way.

Any comment is appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T06:24:01+00:00Added an answer on June 10, 2026 at 6:24 am

    I found an interesting solution here: http://blog.plover.com/math/choose.html

        unsigned choose(unsigned n, unsigned k) {
          unsigned r = 1;
          unsigned d;
          if (k > n) return 0;
          for (d=1; d <= k; d++) {
            r *= n--;
            r /= d;
          }
          return r;
        }
    

    This avoids overflows (or at least limits the problem) by performing multiplication and division alternatively.

    E.g. for n = 8, k = 4:

    result = 1;
    result *= 8;
    result /= 1;
    result *= 7;
    result /= 2;
    result *= 6;
    result /= 3;
    result *= 5;
    result /= 4;
    done
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I was solving a programming problem, which wants to find the SYMMETRIC DIFFERENCE between
I was practising the algorithm based programming problem.I am having difficulty,in solving this problem.I
I have a question about solving UI freezing. Introduction: I am currently programming an
I was practicing the dynamic programming problem on SPOJ. But I have no idea
I watched Dynamic Programming - Kapsack Problem (YouTube) . However, I am solving a
I'm stuck in a problem in which I need to calculate something like: ((500!)/(20!x20!x20!x20!...))
I have a problem to solve like this. there is time interval, and each
I'm currently solving a programming problem to enhance my skills (I'm still a newbie)
While solving any programming problem, what is your modus operandi ? How do you
I'm solving UVA's Edit Step Ladders on an uva sub-site named programming-challenges.com, but since

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.