Cod sursa(job #1873748)

Utilizator ajajajEuuuuu ajajaj Data 9 februarie 2017 13:07:05
Problema Factorial Scor 95
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=0;
    int end=5*P;
    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;
}