Acm:poj 1401 factorial-Number theory topic-water problem

Source: Internet
Author: User

POJ 1401FactorialTime limit:1500MS Memory Limit:65536KB 64bit IO Format:%lld &%llu< /c8>

Description

The most important part of a GSM network are so called Base Transceiver Station (BTS). These transceivers form the areas called cells (this term gave the name to the cellular phone) and every phone connects to The BTS with the strongest signal (in a little simplified view). Of course, btses need some attention and technicians need to check their function periodically.

ACM technicians faced a very interesting problem recently. Given a set of btses to visit, they needed to find the shortest path to visit all of the Given points and return back to T He central Company building. Programmers has spent several months studying this problem, with no results. They were unable to find the solution fast enough. After a long time, one of the programmers found this problem in a conference article. Unfortunately, he found that the problem are so called "travelling salesman problem" and it's very hard to solve. If we have N btses to is visited, we can visit them in any order, giving us N! possibilities to examine. The function expressing is called factorial and can be computed as a product 1.2.3.4....N. The number is very high even for a relatively small N.

The programmers understood they had no chance to solve the problem. But because they has already received the grant from the government, they needed to continue with their studies and produce at least some results. So they started to study behaviour of the factorial function.

For example, they defined the function Z. For any positive integer N, Z (n) are the number of zeros at the end of the decimal form of number n!. They noticed that this function never decreases. If We have both numbers N1 < N2, then Z (N1) <= Z (N2). It is the because we can never "lose" any trailing zero by multiplying by any positive number. We can only get new and new zeros. The function Z is very interesting, so we need a computer program, which can determine its value efficiently.

Input

There is a single positive an integer T on the first line of input. IT stands for the number of numbers to follow. Then there are T lines, each containing exactly one positive integer number N, 1 <= N <= 1000000000.

Output

For every number N, output a single line containing the single non-negative integer Z (N).

Sample Input

63601001024234568735373

Sample Output

0142425358612183837

/* /test Instructions: The number of n! suffix 0; it is important to note that only a multiplier of 2 and a multiplier of 5 will produce a suffix of 0; there is no doubt that the multiples of 2 are more than 5, so as long as the number of multiples of 5 is counted, but note that the 5^n can produce n suffixes 0; So we have to deal with 5^i All 5 multiples of all add up, see the code for details; AC Code/* /

#include "map" #include "Cmath" #include "string" #include "Cstdio" #include "vector" #include "CString" #include "iostream "#include" algorithm "using namespace Std;typedef long long ll;const int mx=202; #define MEMSET (x, y) memset (x,y,sizeof (×)) #define FK (x) cout<< "" "<<x<<" "" <<endlll ans (int n) {LL ans = 0;for (int i=5; n/i>0; i*=5) {
   
    //5 can produce a multiple of 1 0,25 can produce 2 0, 125 multiples can produce 3 0, and so on ... ans+=n/i;} return ans;} int main () {int t,x;scanf ("%d", &t), while (t--) {scanf ("%d", &x);p rintf ("%d\n", ans (x));}}
   

  

Acm:poj 1401 factorial-Number theory topic-water problem

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.