Cod sursa(job #3378896)

Utilizator Lapush05alexandru Lapush05 Data 28 noiembrie 2026 19:03:23
Problema Factorial Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.58 kb
// Source: https://usaco.guide/general/io

#include <bits/stdc++.h>
#define int long long
using namespace std;

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

signed main() {
    ifstream cin("fact.in");
    ofstream cout("fact.out");
	int p;
    cin >>p;
    int st=1;
    int dr=5e8;
    int s=-1;
    while(st<=dr)
    {
        int mid=(st+dr)/2;
        if(z(mid)>=p)
        {
            s=mid;
            dr=mid-1;
        }
        else
        {
            st=mid+1;
        }
    }
    if(z(s)!=p)cout<<"-1\n";else
  cout<<s<<"\n";
  return 0;
}