Cod sursa(job #1423727)

Utilizator zacuscaAlex Iordache zacusca Data 22 aprilie 2015 14:23:48
Problema Factorial Scor 90
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.59 kb
#include<fstream>
using namespace std;
ifstream in("fact.in");
ofstream out("fact.out");
int p,n,sol;
int nr0(int x)
{
    int cnt=0;
    int p=5;
    while(p<=x)
    {
        cnt+=x/p;
        p*=5;
    }
    return cnt;
}
int main()
{
    in>>p;
    if(!p)out<<"1\n";
    int st=1,dr=5*p;
    while(st<=dr)
    {
        int m=(dr+st)/2;
        int aux=nr0(m);
        if(aux==p)
        {
            sol=m;
            dr=m-1;
        }
        else if(aux>p)
            dr=m-1;
        else st=m+1;
    }
    out<<sol<<'\n';
    out.close();
    return 0;
}