Cod sursa(job #1364576)

Utilizator alexvamesuAlex Vamesu alexvamesu Data 27 februarie 2015 18:44:11
Problema Factorial Scor 90
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.47 kb
#include <fstream>
#include <cmath>
using namespace std;
ifstream f("fact.in");
ofstream g("fact.out");
int main()
{
    long long P,x=0,a=5,N,ls,ld,Nmax=400000015,b=0;
    f>>P;
    if(P==0) g<<1;
    ls=5;ld=Nmax;b=0;
    while(ls<=ld and b==0)
    {
       N=(ls+ld)/2;
       x=0;
       a=5;
       while(a<=N)
       {
           x=x+N/a;
           a=a*5;
       }
    if(x==P) {g<<N/5*5;b=1;}
    else if(x<P) ls=N+1;
         else ld=N-1;
    }
}