Cod sursa(job #1563599)

Utilizator xtreme77Patrick Sava xtreme77 Data 6 ianuarie 2016 12:52:46
Problema Factorial Scor 95
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.85 kb
#include <fstream>

using namespace std;

ifstream cin ( "fact.in" ) ;
ofstream cout ( "fact.out" ) ;

long long nrzero ( int n )
{
    long long put = 5 ;
    int sol = 0 ;
    while ( put < n )
    {
        sol += ( int ) n / put ;
        put *= 5 ;
    }
    return sol ;
}

int main()
{
    int p ;
    cin >> p ;
    int st = 1 ;
    int dr = 1e9 ;
    int gasit = -1 ;
    while ( st <= dr )
    {
        int mij = ( st + dr ) / 2 ;
        if ( nrzero ( mij ) < p )
        {
            st = mij + 1 ;
        }
        else {
            dr = mij - 1 ;
            if ( nrzero ( mij ) == p )
            gasit = mij ;
        }
    }
    if ( gasit == -1 ) {
        cout << -1 ;
    }
    else {
        if ( gasit >= 5 )
        cout << gasit - gasit % 5 ;
        else cout << 1 ;
    }
    return 0;
}