Cod sursa(job #3370728)

Utilizator DoctorMathDoctor Math DoctorMath Data 27 octombrie 2026 00:48:27
Problema Factorial Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.49 kb
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

#define int long long

int z(int n){
  int s=0;
  while (n){
    n/=5;
    s+=n;
  }
  return s;
}

signed main() {
  freopen("fact.in","r",stdin);
  freopen("fact.out","w",stdout);
  int n;cin>>n;
  int l=1,r=(int)1e9,s=-1;
  while(l<=r){
    int m=(l+r)/2;
    if(z(m)>=n){
      s=m;
      r=m-1;
    }else{
      l=m+1;
    }
  }
  if(z(s)!=n)cout<<"-1\n";else
  cout<<s<<"\n";
  return 0;
}