Cod sursa(job #1603803)

Utilizator gorni97aaa aaa gorni97 Data 17 februarie 2016 19:31:49
Problema Factorial Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.56 kb
#include <iostream>
#include <fstream>
using namespace std;

int zero(int n)
{int nr=0;
    while(n>=5)
{nr=nr+n/5;
n=n/5;
}

return nr;

}


int main()

{long li,ls,k,p,minim,gasit;
fstream f("fact.in",ios::in);
fstream g("fact.out",ios::out);
f>>p;

li=1;
ls=2e9;
gasit=1;

if(p==0)
    g<<1;
else

{
while((li<=ls)&&(gasit==1))
{
    k=(li+ls)/2;


if(zero(k)==p)
    gasit=0;

if(zero(k)<p)
    li=k+1;
else
    ls=k-1;

}

if(zero(k)==p)
   {while(k%5!=0)
   k--;
   g<<k;}
   else
    g<<-1;

   }

}