Cod sursa(job #1064097)

Utilizator dtz.petricanPetrican Danut dtz.petrican Data 21 decembrie 2013 15:13:12
Problema Factorial Scor 100
Compilator cpp Status done
Runda riad Marime 0.71 kb
#include<fstream>
#include<math.h>
using namespace std;
long long sol=-1,p,t=0;
int verif(long long a)
{
    long long s=0,b=1;
    while(b<=a)
    {
        b*=5;
        s+=a/b;
    }
    if(s>=p)
    {
        t=s;
        return 1;
    }
    return 0;
}
void bin2()
{
    long long poz=0;
    long long pas=(1<<30);
    while(pas>0)
    {
            if( verif(poz+pas)==1)
                    sol=poz+pas;
                else poz+=pas;
        pas>>=1;
    }
}
int main()
{
    ifstream fcin("fact.in");
    ofstream fcout("fact.out");
    fcin>>p;
    if(p==0)fcout<<1;
    else
    {
    bin2();
    if(t!=p)fcout<<-1;
    else
        fcout<<sol;
    }
    return 0;
}