1024! There are several zeros at the end

Source: Internet
Author: User

Not a multiple of 5, no matter which one is multiplied, the result of a single digit being 0 is impossible.

25*4 = 100, can generate two 0, the same is true (75 = 25*3 = 5*5
* 3) * 4 = 300; (125 = 5*5*5) * 8 = 1000;

That is, the number of factors 5 in a number can be multiplied by enough even numbers to generate the last 0 of the same number.

Summary: The number of the last 0 in the factorial of N is: N/5 + N/25 + N/125 ......

#include <stdio.h>int zero_count(int n);int main(int argc ,char *argv[]){printf("zero_count is %d...\n", zero_count(1024));return 0;}int zero_count(int n){int count = 0;while(n > 0) {n = n/5;count += n;}return count;}

Running result: 253

Analysis:

Number of multiples of 5: 1024/5 = 204
The number is a multiple of 25: 1024/25 = 40
Number of multiples of 125: 1024/125 = 8
Which is a multiple of 625: 1024/625 = 1

Therefore, the result is 253.

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.