Fast computing n! The number of prime factors

Disclaimer: This article is a blogger original article, follow the CC 4.0 BY-SA copyright agreement, reproduced, please attach the original source link and this statement.
This link: https://blog.csdn.net/weixin_42557561/article/details/100014440

Learning
us a sample to explain:

12345678 8 we find! 2 the number
 111 First we calculate the number of multiples of 2: 8/2 = 4
   . 1. 1 Next we calculate the number of a multiple of 4: 8/4 = 2
      1 Last we solve a third the number of layers is 2: 8/8 = 1

We have 4 + 2 + 1 = 7, so there have been a total of seven 2.

which is:
c n t ( x ) = [ n / ( x 1 ) ] + [ n / ( x 2 ) ] + [ n / ( x 3 ) ] + . . . cnt (x) = [n / (x ^ 1)] + [n / (x ^ 2)] + [n / (x ^ 3)] + ... (Until power x is larger than n)
Here we can see: The method we usually find that a one demand (that is, every number count again), and this way we each row seek each row, although the effect the same, but for up fast. worth learning.

Guess you like

Origin blog.csdn.net/weixin_42557561/article/details/100014440