Cod sursa(job #1685014)

Utilizator flibiaVisanu Cristian flibia Data 11 aprilie 2016 13:59:59
Problema Factorial Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.75 kb
#include <fstream>
#include <iostream>
#include <climits>
 
using namespace std;
 
ifstream in("fact.in");
ofstream out("fact.out");
 
int n;
long long st = 1, dr = LLONG_MAX-3, piv;
 
long long lol(long long x)
{
    long long y = 0;
    long long p = 5;
    while(p <= x)
    {
        y += (x / p);
        p *= 5;
    }
    return y;
} 
    
void search()
{   
        while(st <= dr)
        {
            piv = st + (dr - st) / 2;
            if(lol(piv) <= n) st = piv + 1;
            else dr = piv - 1;
        }
        if(lol(st - 5) == n) out << st - 5;
        else out << "-1"; 
}
 
int main()
{
    in >> n;
    if(n == 0) out << "1"; else search();
    //cout << lol(50);
    //cin >> n;
    return 0;
}