Cod sursa(job #2131659)

Utilizator ioanaa_ghGhiorghi Ioana-Cristina ioanaa_gh Data 14 februarie 2018 20:34:19
Problema Factorial Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.61 kb
#include <bits/stdc++.h>
using namespace std;
ifstream fin("fact.in");
ofstream fout("fact.out");
long long p;
int zero(int x)
{
    long long s = 0;
    while(x >= 5)
    {
        s = s + x / 5;
        x = x / 5;
    }
    return s;
}
int cautbin(int x)
{
    long long st = 0, mij, dr=1000000000;
    while(st < dr)
    {
        mij = (st + dr)/2;
        if(zero(mij) > p)dr = mij;
        else st = mij +1;
    }
    st -= 5;
    return st;
}


int main()
{
   fin >> p;
   if(p == 0)fout << 1;
   else if(zero(cautbin(p)) != p)
            fout << "-1";
   else fout << cautbin(p);
}