Cod sursa(job #1367913)

Utilizator mihitudorMihalcea Tudor mihitudor Data 2 martie 2015 11:29:58
Problema Factorial Scor 5
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.73 kb
#include <fstream>
#include <iostream>
#define maxx 400000015
using namespace std;
int main ()
{
    unsigned long long n=0, p, z, y, d=maxx, s=5, x=0;
    ifstream f("fact.in");
    ofstream g("fact.out");
    f>>p;
    if(p==0)
        g<<1;
    else
    {
        while(s<=d && x==0)
        {
            n=(s+d)/2;
            z=0;
            y=5;
            while(y<=n)
            {
                x=x+n/y;
                y=y*5;
            }
            if(x==p)
            {
                g<<n/5*5;
                x=1;
            }
            else if(x<p)
                s=n+1;
            else
                d=n-1;
        }

        if(x==0)
            g<<-1;
    }
    return 0;
}