Poj1401 calculates the number of zeros at the end of the N factorial.

Source: Internet
Author: User

The question is quite scary. There will be more than 0 in 2*5, and more than 0 in 10. There will be more than two 0 in 25*4. This will be messy .... the conclusion is that N can be used! To make a qualitative factor decomposition, there must be a 5 ^ x item in it. The goal is to evaluate the value of X. That is to say, the number of five is 0. Then I started to traverse from 1 to n and started to use 5 Except, and then timed out. Later, I thought about how to simply remove 5, 5 ^ 2, and 5 ^ 3,CodeUltra short .....

# Include <stdio. h> int Cal (INT num) {int sum = 0; int I; for (I = 5; I <= num; I * = 5) {sum + = (Num/I);} return sum;} int main (void) {int t; int num; scanf ("% d", & T ); while (t --) {scanf ("% d", & num); printf ("% d \ n", Cal (Num);} return 0 ;}

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.