Cod sursa(job #982791)

Utilizator AeroHHorea Stefan AeroH Data 10 august 2013 00:08:45
Problema Factorial Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.07 kb
//#include <iostream>
#include <fstream>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <utility>
#define ll long long int
#include <cstdio>
#define first f
#define second s
#define fi(n) for(i=0;i<n;++i)
#define fj(n) for(j=0;j<n;++j)
#define fk(n) for(k=0;k<n;++k)
using namespace std;
ifstream cin("fact.in");
ofstream cout("fact.out");
ll i,j,k,n,p,rasp,aux;
int cinci[] = {1,5,25,125,625,3125,15625,78125,390625,1953125,9765625,48828125,244140625,1220703125};
int valor[] = {0,1,6,31,156,781,3906,19531,97656,488281,2441406,12207031,61035156,305175781};

int decompose(int n)
{
    int d=5,x=0;
    while(d<=n)
    {
        x+=n/d;
        d*=5;
    }
    return x;
}


int main ()
{
ios_base::sync_with_stdio(false);
cin>>p;
if (p==0)
{
    cout<<1;
    return 0;
}
int st=0;
int dr=1000000000;
while (st<=dr)
{
    int mij=(st+dr)/2;
    rasp=decompose(mij);
    if (rasp==p&&mij%5==0){cout<<mij<<'\n';return 0;}
    if (rasp<p)st=mij+1;
    else dr=mij-1;

}
cout<<-1<<'\n';

    return 0;
}