Cod sursa(job #1292138)

Utilizator wGEORGEWGeorge Cioti wGEORGEW Data 13 decembrie 2014 18:03:11
Problema Factorial Scor 90
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.58 kb
#include <iostream>
#include <fstream>
#include <math.h>
#include <algorithm>

using namespace std;

int main()
{
    ifstream f("fact.in");
    ofstream g("fact.out");
    long p ,mul ,m5 ,s ,d ,m ,aux,bun=0;
    f>>p;
    s=1;
    d=400000015;
    if(p==0)
    g<<"1";
    else
    {
    while(s<d)
    {
        m=(s+d)/2;
        mul=0;
        m5=5;
        while(m>=m5)
        {
            mul+=m/m5;
            m5*=5;
        }
        if(mul<p)
        s=m+1;
        else
        if(mul>=p)
        d=m;
    }
    g<<s;
    }
    return 0;
}