I have no idea on how to solve this one:
Ana learned about permutations. She knows that there are
n!
(n factorial) ways to order the
n
elements, and she knows that
n! = 1*2*3*...*(n-1)*n
.
She found that as how the number (n) grows, the number of zeros will grow too. Thus she asked
i
questions like: which is the lowest integer whoms factorial will end with exactly
Xi
zeros?
Help Ana answer the questions.
On the first line of file "zero.in" will be a number
T
(number of tests), and the next
T
lines will contain each a
Xi
number.
In the file "zero.out" there will be
T
lines. On the line
i
there will be the answer for
Xi
. If there is no solution print
-1
.
0 < Xi < 1 000 000
1 < T < 10
Example
1 2 3 4 5 6 7 8 9 10 11 12
|
Zero.in
4
1
2
5
24
Zero.out
5 | As 5! = 120
10 | As 10! = 3 628 800
-1 | As there is no factorial ending with 5 zeros.
100 | As 24! has 100 zeros.
|
I have no idea how to do this...
PS: Sorry for bad translation of text.
When I got almost ready, I found out I did the vice-versa of what the problem requests:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
|
#include <iostream>
#include <fstream>
#include <cmath>
using namespace std;
int factorial(int nr)
{
return (nr == 1 || nr == 0) ? 1 : factorial(nr - 1) * n;
}
int main(void)
{
typedef long long intreg;
intreg n,Xi,numar,aux;
int T,i,cif,k=0;
ifstream inFisier("zero.in");
ofstream outFisier("zero.out");
if (!inFisier.is_open() || !outFisier.is_open())
{
cout << "Error 404: File not found";
return 1;
}
else
{
inFisier >> T;
for (i = 1; i <= T; ++i)
{
inFisier >> Xi;
numar = factorial(Xi);
aux = numar;
while (aux != 0)
{
cif = aux % 10;
aux = aux / 10;
if (cif == 0)
{
k++;
}
else
continue;
}
if (k == Xi)
// When I got here I figured out I did something else >.>
}
}
}
|