Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

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

2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

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

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report