Cod sursa(job #1424849)

Utilizator Firealex2Rotileanu Alexandru Firealex2 Data 25 aprilie 2015 16:12:48
Problema Factorial Scor 10
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.44 kb
#include <iostream>
#include <fstream>

using namespace std;
ifstream fi("fact.in");
ofstream fo("fact.out");
int zero(int n){
  int nr=0;
  while(n>=5)
  {
    nr+=n/5;
    n/=5;

  }
  return nr;

}
int cb(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()
{
    int nr,s;
    fi>>nr;
    s=cb(nr);
    if(zero(s)==s)
      fo<<s;
    else
      fo<<"-1";


return 0;
}