Cod sursa(job #1670884)

Utilizator pimao2004Lupu Stefan Dragos pimao2004 Data 1 aprilie 2016 09:55:10
Problema Factorial Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.87 kb
#include <fstream>
#include <climits>
/*#INCLUDE <VALOARE>
#INCLUDE <BO$$>
#INCLUDE <NOT_BUREA>
#INCLUDE <BIBLIA>
#INCLUDE <DUMNIZO>
#INCLUDE <HAI_CU_100>
#INCLUDE <DESTROY_CIOCIEA_CEL_CIOCIT_DE_CIOACA_CIOCISMULUI_DE_CIOCI>*/
using namespace std;
ifstream in("fact.in");
ofstream out("fact.out");
long long n,ra,rez=100000000000,num;
int verif(long long nr)
{
    long long d=1,c=0;
    while(nr/d)
    {
        d=d*5;
        c+=nr/d;
    }
    if(c==n)
        num=nr;
    if(c>=n)
        return 1;
    else
        if(c<n) return 0;
}
long long caut_bin()
{
    long long st,dr=10000000000,mij;
    st=1;
    while(st<=dr)
    {
        mij=(st+dr)/2;
        ra=verif(mij);
        if(ra==1) dr=mij-1;
        else st=mij+1;
    }
    return st;
}
int main()
{
    in>>n;
    if(caut_bin()==num) out<<num;
    else out<<-1;
    return 0;
}