Cod sursa(job #2333737)

Utilizator BungerNadejde George Bunger Data 1 februarie 2019 21:31:05
Problema Factorial Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.69 kb
#include <bits/stdc++.h>

using namespace std;
ifstream fin ("fact.in");
ofstream fout ("fact.out");
int n,p;
long long ans-1;
int zero(int x)
{
    int nr=0;
    int fact=5;
    while(x>=fact)
    {
        nr+=x/fact;
        fact=5*fact;
    }
    return nr;
}
void solve()
{
    int st=1,dr=1e8,mij;
    while(st<=dr)
    {
        mij=st+(dr-st)/2;
        int rez=zero(mij);
        if(rez==p)
        {
            ans=mij;
            dr=mij-1;
        }
        else if(rez<p)
        {
            st=mij+1;
        }
        else
        {
            dr=mij-1;
        }
    }
    fout<<ans;
}
int main()
{
    fin>>p;
    solve();
    return 0;
}