Cod sursa(job #288446)

Utilizator ucc_5Usurelu Catalin ucc_5 Data 25 martie 2009 19:55:38
Problema Factorial Scor 10
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.55 kb
#include <fstream.h>

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

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

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