Cod sursa(job #2588611)

Utilizator Sup_m8sDan Pagel Sup_m8s Data 25 martie 2020 00:59:50
Problema Factorial Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.47 kb
#include <iostream>
#include <cmath>
using namespace std;
int nr5(int x){
  int s=0;
  for(int n=5;n<=x;n*=5){
    s+=x/n;
  }
  return s;
}


int main(int argc, char const *argv[])
{
  int p,li=0,mid,lf,gas=-1,k;
  cin>>p;
  lf=p;
  if(p==0)cout<<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)cout<<-1;
  else cout<<gas;
  }
  return 0;
}