Cod sursa(job #1911382)

Utilizator tudorcebereTudor Cebere tudorcebere Data 7 martie 2017 20:19:17
Problema Factorial Scor 50
Compilator c Status done
Runda Arhiva de probleme Marime 0.67 kb
#include<stdio.h>
#include<stdlib.h>
int verifica_zero( long long x)
{
  long long cota = 5, f = 0;
  while(cota < x)
  {
    f += x/cota;
    cota = cota * 5;
  }
  return f;
}
int main()
{
  int P = 0, mijloc = 0;
  FILE *f_in = fopen("fact.in", "rt");
  fscanf(f_in, "%d", &P);
  FILE *f_out = fopen("fact.out", "wt");
  long long int i = 0, s = 100000000;
  if(P <= 0)
  {
    fprintf(f_out, "1");
  }
  else
  {
    while(s > i)
    {
      mijloc = (s + i)/2;
      if(verifica_zero(mijloc) < P)
        i = mijloc + 1;
      else
        s = mijloc;
    }

    if(verifica_zero(i) != P)
      fprintf(f_out, "-1");
    else
      fprintf(f_out, "%lld", i);
  }
  return 0;
}