N! How many 0 (go language implementations) are included in the results

Source: Internet
Author: User
This is a creation in Article, where the information may have evolved or changed.

N! How many 0 (go language implementations) are included in the results

Detailed explanation See code comment

Package Mainimport ("FMT") type myInt int32/** statistical factorial n! Number of results in 0 * Method 1: Statistics 5 occurrences of the number of times * 25 appeared two 5* because any one even can and 5 composition 10* and even quantity is sufficient */func fZereCount1 (n myInt) myInt {var count, I myInt = 0, 0/ /full enumeration for; n >= 5; n--{i = n//i value is not equal to 0, so there is no need to add && i > 0for i%5 = = 0 {count++i/= 5}}return count}/** Method 1 The second way */func fzerecount1x ( n myInt) myInt {var i, count, tmp myInt = 1, 0, 0//part enumeration for {if 5*i <= n {count++tmp = i//There may be I value also satisfies the condition for tmp%5 = 0 {Coun T++tmp/= 5}i++} else {return Count}}return count}/** Method 2: Quick Statistics/* For example: 199*count=[199/5]+[199/5/5]+[199/5/5/5]* explanation: [199/5] That is, how many of the 199 can be divisible by 5 (rounding) * [199/5/5] that is, how many of the 199 can be divisible by 25 (rounding) * [199/5/5] that is, how many 199 can be divisible by 125 (rounding) * Special number: 125, can be 5, 25 can also be divisible by 75, so need to be counted 3 times * Summary: This method is essentially the number of statistics 5 */func fZereCount2 (n myInt) myInt {var count, tmp myInt = 0, 0for {tmp = n/5if TM p > 0 {n = tmpcount + tmp} else {return Count}}return count}/** code author: Days of Blog: http://blog.csdn.net/WAPWO?viewmode=content S */func Main () {FMT. Println (FZereCount1 (10000)) FMT. Println (FZERECOUNT1X (10000)) FMT. Println (fZeReCount2 (10000))} 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.