Cod sursa(job #2480103)

Utilizator emanuel27iIonescu Emanuel emanuel27i Data 24 octombrie 2019 21:46:06
Problema Factorial Scor 25
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.53 kb
#include <iostream>
#include <fstream>

using namespace std;

ifstream fin("fact.in");
ofstream fout("fact.out");

int fact0(int n)
{
	int nr=0,p=5;
    while(p<=n)
    {
        nr+=n/p;
        p*=5;
    }
    return nr;
}

int main()
{
    int p,n,st=0,dr=10000000,k=-1;
    fin>>p;
    while(st<=dr)
    {
        n=(st+dr)/2;
        if(p==fact0(n))
            k=n;
        if(fact0(n)>=p)
            dr=n-1;
        else
            st=n+1;
    }
    if(k!=-1)
    fout<<k;
    else
    fout<<-1;
}