Cod sursa(job #2588618)

Utilizator Sup_m8sDan Pagel Sup_m8s Data 25 martie 2020 01:40:39
Problema Factorial Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.54 kb
#include <iostream>
#include <cmath>
#include <fstream>
using namespace std;
ifstream f("fact.in");
ofstream g("fact.out");
int nr5(int x){
  long long int s=0;
  for(int n=5;n<=x and n;n*=5){
    s+=x/n;
  }
  return s;
}


int main(int argc, char const *argv[])
{
  int p,li=0,mid,lf,gas=-1,k;
  f>>p;
  lf=p;
  if(p==0)g<<1;
  else{
  do{
    mid=(li+lf)/2;
    k=nr5(5*mid);
    if(k==p)gas=5*mid;
    else if(k>p)lf=mid-1;
    else li=mid+1;
  }while(li<=lf && k!=p);
  if(gas==-1)g<<-1;
  else g<<gas;
  }
  return 0;
}