Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

How does C++ count the number of a factorial 0?

Shulou Source: shulou.com Published: 2022-06-01 16:27:27 11月09日 Update

This article mainly explains how C++ counts the number of multiplications of zeros. Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Next let the editor to take you to learn "C++ how to count a factorial 0" bar!

Here, the calculation formula is given first, and then the derivation process is given.

Let f (x) denote the number of zeros at the end of a positive integer x, then:

When 0

< n < 5时,f(n!) = 0; 当n >

When = 5, f (n!) = k + f (k!), where k = n / 5 (rounded).

Calculation example

F (5!) = 1 + f (1!) = 1

F (10!) = 2 + f (2!) = 2

F (20!) = 4 + f (4!) = 4

F (100!) = 20 + f (20!) = 20 + 4 + f (4!) = 24

F (1000!) = 200 + 40 + f (40!) = 240 + 8 + f (8!) = 248 + 1 + f (1) = 249

# include using namespace std;int CountZero (int n) {if (nx5) {n = count 5; count = count + n;} return count;} int main () {int N; cin > > N; cout

Tags: Number factorial cantilever statistics content learning practical deeper formula interest practicality practical simple operation integer method more friends end website process Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Information Linux Huawei Shulou Tech Info macOS