Cod sursa(job #2552202)

Utilizator cristiemanuelstroe cristian emanuel cristiemanuel Data 20 februarie 2020 17:46:00
Problema Factorial Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.6 kb
#include    <bits/stdc++.h>
#define ll long long

using namespace std;

ifstream fin("fact.in");
ofstream fout("fact.out");

int n,cnt,nr,p;

int nr_zero(int t)
{
int     P=5,s=0;
    while(t>=P)
      s+=t/P,P*=5;
    return s;
}

int main()

{
    fin>>p;
    if(!p) {fout<<1;return 0;}
    int st=1,dr=2000000000;
    while(st<=dr)
    {
        int mij=(st+dr)/2;
        int x=nr_zero(mij);
        if(x==p){
          fout<<mij-mij%5;
          return 0;
        }
          else if(x>p)
          dr=mij-1;
          else
            st=mij+1;
    }
    fout<<-1;
}