Cod sursa(job #288534)

Utilizator ucc_5Usurelu Catalin ucc_5 Data 25 martie 2009 21:27:59
Problema Factorial Scor 95
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.54 kb
#include <fstream.h>

ifstream f("fact.in");
ofstream g("fact.out");
long p;

long fact (long n)
{ long nr_0=0,aux;
  while (n)
  { nr_0+=n/5;
    n/=5;
  }
  return nr_0;
}

int caut_bin(long val)
{
   long i, step;
   for (step = 1; step < 1000000000; step <<= 1);
    for (i = 0; step; step >>= 1)
	if (i + step <= 1000000000 && fact (i + step) <= val)
	   i += step;
    if (fact(i)==p) return i;
     else return -1;
}
int main ()
{ f>>p;
  long aux=caut_bin(p);
  if (aux!=-1) aux=aux-(aux%5);
  g<<aux;
  return 0;
}