Cod sursa(job #1326905)

Utilizator vladttturcuman vlad vladtt Data 26 ianuarie 2015 10:24:15
Problema Factorial Scor 90
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.77 kb
#include <fstream>
#define N_MAX 500000000

using namespace std;
ifstream fin("fact.in");
ofstream fout("fact.out");

long mj,s,d,er,x,qw[20];


long zero()
{
    long t=0;
    for(int j=1;j<=12;j++)
        t=t+mj/qw[j];
    return t;
}

int putere_5()
{
    qw[0]=1;
    for(int i=1;i<=12;i++)
        qw[i]=qw[i-1]*5;
    return 0;
}

int main()
{
    putere_5();
    fin>>x;
    if(x==0)
    {
        fout<<1;
        return 0;
    }
    s=1;
    d=N_MAX;
    mj=(N_MAX+1)/2;
    while(s<=d)
    {
        er=zero();
        if(er>x) d=mj-1;
        else
            if(er<x) s=mj+1;
            else
            {
                fout<<mj-mj%5<<'\n';
                return 0;
            }
        mj=(d+s)/2;
    }
    return 0;
}