Cod sursa(job #1173980)

Utilizator costyrazvyTudor Costin Razvan costyrazvy Data 21 aprilie 2014 15:40:22
Problema Factorial Scor 20
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.13 kb
#include <fstream>
#include <vector>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <queue>
#include <cstring>
/*#include <iostream>
#define f cin
#define g cout*/
#define max(a,b) ((a>b) ? a : b)
#define min(a,b) ((a<b) ? a : b)
#define FORC(i,x,y,t) for (i=x;i<=y;i+=t)
#define FOR(i,x,t) for (i=1;i<=x;i+=t)
#define FORD(i,x,y,t) for (i=x;i>=y;i-=t)
#define LL long long
#define LiteraMica islower
#define LiteraMare isupper
#define Cifra isdigit
#define Gol(Vector,x) memset(Vector,x,sizeof(Vector))
using namespace std;
LL P;
ifstream f("fact.in");
ofstream g("fact.out");
LL pow(LL x,LL p)
{
    LL i,Px=1;
    FOR(i,p,1) Px*=x;
    return Px;
}
LL Zeros(LL x)
{
    LL i,Nr=0;
    FOR(i,25,1)
        Nr+=(x/pow(5,i));
    return Nr;
}
void Solve()
{
    LL st=1,dr=pow(10,18),mij=0,ans=0;
    while (st<=dr)
     {
         mij=(st+dr)/2;
         ans=Zeros(mij);
         if (ans==P) {g<<mij<<'\n';return;}
         if (ans>P) dr=mij-1;
            else st=mij+1;
     }
    g<<"-1"<<'\n';
}
int main()
{
    f>>P;
    Solve();
    f.close();
    g.close();
    return 0;
}