Cod sursa(job #2276111)

Utilizator hutanuHutanu Andrei hutanu Data 4 noiembrie 2018 10:43:24
Problema Factorial Scor 15
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.59 kb
#include <fstream>
using namespace std;
ifstream fin("fact.in");
ofstream fout("fact.out");
int main()
{
    int p,n,st,dr,m,cm,nr,y;
    fin>>p;
    nr=0;
    y=5;
    st=1;
    dr=2e9;
    while(st==dr)
    {
        m=(st+dr)/2;
        n=0;
        cm=m;
        y=5;
        while(y<=cm)
        {
            nr=cm/y;
            y=y+5;
        }
        if(nr<p)
            st=m+1;
        else
            dr=m-1;

    }
    while(y<=st)
    {
        nr=st/5;
        y=y+5;
    }
    if(nr==p)
        fout<<st;
    else
        fout<<-1;
    return 0;
}