Cod sursa(job #2210187)

Utilizator markerenaMark Erena markerena Data 5 iunie 2018 20:31:11
Problema Factorial Scor 10
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.79 kb
#include <fstream>

using namespace std;
int f(int n)
{
    int ci,p5=n/5;
    for(int i=25;i<=n;i+=25)
    {
        ci=i;
        while(ci%25==0)
        {
            p5++;
            ci/=25;
        }
    }
    return p5;
}
int main()
{
    ifstream in ("fact.in");
    ofstream out ("fact.out");
    int p,st=1,dr,mid;
    long long rez=-1;
    in>>p;
    dr=5*p;
    if(p==0)
        out<<1;
    else
    {
        while(st<=dr)
        {
            mid=(st+dr)/2;
            if(f(mid)>p)
                dr=mid-1;
            else
                if(f(mid)<p)
                    st=mid+1;
                else
                {
                    rez=mid;
                    dr=mid-1;
                }
        }
        out<<rez;
    }
    return 0;
}