Cod sursa(job #2470687)

Utilizator AlexPopescuPopescu Alexandru AlexPopescu Data 9 octombrie 2019 17:55:18
Problema Factorial Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.77 kb
#include <iostream>
#include  <cstdio>
#include <cmath>
#include <climits>
using namespace std;
  int nrof(long long n)
      { int p5=5,s=0;
         while(n>=p5)
            { s+=n/p5;
               p5*=5;
            }

      return s;
      }


using namespace std;


int main()
{ freopen("fact.in","r",stdin);
   freopen("fact.out","w",stdout);
      long long N,p;
    scanf("%d",&p);
      int ls;
       int li=1;ls=INT_MAX;
        while(li<=ls)
             { int mij=(li+ls)/2;
                  int n0=nrof(mij);
                      if(n0>=p)
                           ls=mij-1;
                          else li=mij+1;
             }
          if(nrof(li)==p) printf("%d",li);
              else printf("-1");



    return 0;
}