Блог пользователя Love_U_JERRY

Автор Love_U_JERRY, 11 лет назад, По-английски

How to calculate factorial of larger integer numbers ( i.e. numbers greater than 20 ) using C/C++ using high precision arithmetic ?

  • Проголосовать: нравится
  • +1
  • Проголосовать: не нравится

»
11 лет назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

Implement big numbers. Like BigInteger in Java.

»
11 лет назад, # |
  Проголосовать: нравится +4 Проголосовать: не нравится

Is there any algorithm can do this in O(logN) or less than O(N) ?

  • »
    »
    11 лет назад, # ^ |
    Rev. 2   Проголосовать: нравится +9 Проголосовать: не нравится

    Factorial grows exponentially. So you need at least O(n) time and memory to calculate it precisely.

    • »
      »
      »
      11 лет назад, # ^ |
        Проголосовать: нравится +1 Проголосовать: не нравится

      Also a^N grows exponentially but we can calculate it in O(logN)

      • »
        »
        »
        »
        11 лет назад, # ^ |
          Проголосовать: нравится +9 Проголосовать: не нравится

        You can calculate it fast unprecisely: either modulo some number or in floating-point type. Anyway, I haven't heard about any fancy factorial calculation algorithms that use less than O(n) arithmetic operations.