Cod sursa(job #1197974)

Utilizator cristinamateiCristina Matei cristinamatei Data 14 iunie 2014 11:12:13
Problema Factorial Scor 25
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.58 kb
#include <fstream>

using namespace std;

int zero( int n )
{
    int nr = 0;
    while( n >= 5 )
    {
        nr += n/5;
        n/=5;
    }
    return nr;
}

int cautare( int p )
{
    int i = 0, pas;
    pas = 1 << 15;
    while( pas != 0 )
    {
        if ( zero(i+pas) < p )
            i+=pas;
        pas/=2;
    }
    return i;
}

int main()
{
    ifstream in("fact.in");
    ofstream out("fact.out");
    int p, aux;
    in >> p;
    aux = cautare(p) + 1;
    if ( zero(aux) == p )
        out << aux;
    else
        out << -1;
    return 0;
}