Cod sursa(job #2074308)

Utilizator verde.cristian2005Verde Flaviu-Cristian verde.cristian2005 Data 24 noiembrie 2017 14:03:12
Problema Factorial Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.64 kb
#include <fstream>
using namespace std;
ifstream in("fact.in");
ofstream out("fact.out");
unsigned long long p;
int verif(unsigned long long n)
{
    unsigned long long cnt=0,cat=0;
    cat=n/5;
    cnt=cat;
    while(cat)
    {
     cat/=5;
     cnt+=cat;
    }
    if(cnt<p)
        return 0;
        if(cnt==p)
            return 2;
    return 1;
}
void cautbin()
{
    unsigned long long r=0,pas=1LL<<63;
    while(pas)
    {
        if(verif(r+pas)==0)
            r+=pas;
        pas/=2;
    }
    if(verif(r+1)==2)
    out<<r+1;
    else
        out<<-1;
}
int main()
{
    in>>p;
    cautbin();
    return 0;
}