Cod sursa(job #1256412)

Utilizator tatianazTatiana Zapirtan tatianaz Data 6 noiembrie 2014 11:09:43
Problema Factorial Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.5 kb
#include <fstream>
using namespace std;

ifstream is("fact.in");
ofstream os("fact.out");

int n, p;

int Nr0(int z)
{
    int cnt = 0;
    while( z >= 5 )
    {
        cnt += z/5;
        z /= 5;
    }
    return cnt;
}


int main()
{
    is >> p;
    long long x = 1 << 30;

    long long i = 0;
    for ( ; x; x >>= 1 )
    {
        if ( Nr0(i + x) < p )
            i += x;

    }

    if ( Nr0(i+1) == p )
        os << i+1;
    else
        os << -1;

    is.close();
    os.close();
    return 0;
}