Cod sursa(job #1686616)

Utilizator JavaAlexDinu Alexandru JavaAlex Data 12 aprilie 2016 12:35:59
Problema Factorial Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.53 kb
#include <stdio.h>

FILE *in, *out;

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

int cmmnr(int p){
  int i=0,pas = 1<<30;
  while(pas != 0){
      if(zero(i+pas) < p)
        i+=pas;
      pas/=2;
  }
  return 1+i;
}
int main()
{
    unsigned int P;
    in = fopen("fact.in" , "r");
    fscanf(in , "%d" , &P);
    out = fopen("fact.out" , "w");
    unsigned int n = cmmnr(P);
    if(zero(n) == P)
      fprintf(out, "%d" , n);
      else
        fprintf(out, "%d" , -1);
    return 0;
}