Cod sursa(job #2022523)

Utilizator ruxandra_lutanRuxandra Lutan ruxandra_lutan Data 16 septembrie 2017 17:54:02
Problema Factorial Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.68 kb
#include <fstream>
using namespace std;
ifstream f("fact.in");
ofstream g("fact.out");
long long m;
int n,p;
int nr_cif_0(int m) {
    if(m==0)
    return 1;
   int rezultat = 0;
   while (m > 0) {
      rezultat += m / 5;
      m /= 5;
   }
   return rezultat;
}
int main()
{
    f>>p;
    int st=0, dr=1e18, ok=0;
    while(st<dr&&ok==0)
    {

        m=(st+dr)/2;
        if(nr_cif_0(m)>p&&ok==0)
            dr=m-1;
        else
            if(nr_cif_0(m)<p)
              st=m+1;
            else
                ok=1;

    }
    if(ok==1)
    {
      while(nr_cif_0(m-1)==p)
        m--;
        g<<m;
    }
    else g<<"-1";

    return 0;
}