Cod sursa(job #1364537)

Utilizator andreip12Pirvulescu Andrei andreip12 Data 27 februarie 2015 18:28:00
Problema Factorial Scor 90
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.62 kb
#include <fstream>
#include <iostream>
#define nmax 400000015
using namespace std;
int main()
{
    unsigned long long n=0,x,f,p,ls=5,ld=nmax,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;
            }


    return 0;

    }
}