Cod sursa(job #1873754)

Utilizator ajajajEuuuuu ajajaj Data 9 februarie 2017 13:15:50
Problema Factorial Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.59 kb
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("fact.in");
ofstream fout("fact.out");
int P,N,start,mid,nr,m;
bool ok=0;
int main()
{
    fin>>P;
    start=1;
    int end=5*P+1;
    while(start<=end)
    {
        mid=(start+end)/2;
        m=mid;
        while(mid!=0)
        {
            nr+=mid/5;
            mid/=5;
        }
        if(nr>=P)
        { if(nr==P)
          {ok=1;
          N=m;}
            end=m-1;
        }else
        start=m+1;
        nr=0;
    }
    if(ok==1)
    fout<<N;
    else
    fout<<-1;
    return 0;
}