# Zoj 2022 factorial

Source: Internet
Author: User

Zoj
2022 factorial

The first question of self a in the IDC room ~

Find the number of consecutive zeros on the tail of the given factorial;

Train of Thought: high requirements on efficiency, so there is no need to doubt that it is a reference to others' ideas. The most intolerable way of thinking: Calculate the factorial and then count ~ The maximum number is 10. How can this problem be solved ~ The most intolerable way of thinking: I found that 0 is multiplied by 5, but for example, 25 has 2 5, and 2 0 will be obtained. The most intolerable way of thinking: count 1 ~ N The number of five of these numbers; the idea is that each five numbers has a 5, and each five shows another 5, so we only need to accumulate N/5 + (n/5/5) + (n/5/5/5) + ...... That's all ...... Khan, another question I'm stupid about ......

Code:

`#include<stdio.h>int main(){int i,n,sum,T;scanf("%d",&T);for(i = 1;i<=T;i++){scanf("%d",&n);sum = 0;while(n/5>0){sum = sum+n/5;n = n/5;}printf("%d\n",sum);}return 0;}`

Related Keywords:

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.