Cannot calculate factorials bigger than 20! ! How to do so?

后端 未结 7 484
清歌不尽
清歌不尽 2020-12-03 08:16

I am using unsigned long long integer format in order to calculate big factorials. However my code fails at some point can you have a look at it? Actually it is part of a la

7条回答
  •  借酒劲吻你
    2020-12-03 08:46

    The limit on an unsigned long long is 18446744073709551615, or about 1.8e+19. 20! is about 2.4e+18, so within range, however 21! is about 5.1e+19, exceeding the maximum size of an unsigned long long.

    You may find this helpful: Are there types bigger than long long int in C++?

提交回复
热议问题