Please subscribe to the official Codeforces channel in Telegram via the link https://t.me/codeforces_official. ×

FluffyPotato's blog

By FluffyPotato, history, 5 years ago, In English

Hello world! There is a choose function in math like "A choose B" notated sometimes like aCb I'm wondering if you can calculate this in O(1) in a program. Given two a and b, calculate a choose b.

You can definitely precompute many values, in an O(ab) loop keeping the factorials, but Can you do it without precomputation? However, precomputing also risks long long overflow. (usually choosing is much lower then the direct factorial value) Thank you

  • Vote: I like it
  • +2
  • Vote: I do not like it

| Write comment?
»
5 years ago, # |
  Vote: I like it 0 Vote: I do not like it

If we don't consider the modulo numbers, it can be solved in $$$O(b)$$$(Not considering the complexity of multiplication or division).

If we consider the modulo numbers, sometimes it can be faster but it requires precomputation.