Cod sursa(job #2078421)

Utilizator severutBogdan Sever-Cristian severut Data 29 noiembrie 2017 15:52:34
Problema Factorial Scor 50
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.63 kb
#include <iostream>
#include <fstream>

using namespace std;

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

int main()
{
    int st,p,dr,mij,x,s,ct,a;
    fin>>p;
    dr=1000000000;
    st=1;
    ct=0;
    while (dr-st>1)
    {
        mij=(st+dr)/2;
        x=mij;
        s=0;
        while (x)
        {
            s+=x/5;
            x=x/5;
        }
        if (s>=p)
            dr=mij;
        else
            st=mij;
    }
    a=st;
    while (a)
    {
        ct+=a/5;
        a/=5;
    }
    if (ct!=s)
        dr=-1;
    if (s==0)
        dr=1;
    fout<<dr;
    return 0;
}