Cod sursa(job #1364562)

Utilizator alexvamesuAlex Vamesu alexvamesu Data 27 februarie 2015 18:39:00
Problema Factoriale Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.64 kb
#include <fstream>
#include <iostream>
#define nmax 400000015
using namespace std;
int main ()
{
    unsigned long long n=0,p,x,f,ld=nmax,ls=5,g=0;
    ifstream h ("fact.in");
    ofstream k ("fact.out");
    h>>p;
    if (p==0)
        k<<1;
    else{
    while (ls<=ld && g==0)
        {
            n=(ls+ld)/2;
            x=0;
            f=5;
            while(f<=n)
            {
                x=x+n/f;
                f=f*5;
            }
            if (x==p){k<<n/5*5;g=1;}
            else if (x<p) ls=n+1;
            else ld=n-1;
        }

        if (g==0)
            k<<-1;
    }

    return 0;
        }