Cod sursa(job #1627159)

Utilizator geo_furduifurdui geo geo_furdui Data 3 martie 2016 14:56:41
Problema Factorial Scor 25
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.59 kb
#include <fstream>
#include<cmath>
using namespace std;
ifstream f("fact.in");
ofstream g("fact.out");
int numar (int n)
{
    int p=5,nr=0;
    while(p<=n)
    {
        nr=nr+n/p;
        p*=5;
    }
    return nr;
}
int main()
{
    int d,st=1,dr=1000000,mij,k,sol;
    f>>k;
    while(st<=dr)
    {mij=(st+dr)/2;
        d=numar(mij);
        if(d>=k)
        { sol=mij;
           dr=mij-1;
        }
        else if(d<k)
        {
            st=mij+1;
        }
    }
     if(numar(sol)==k) g<<sol; else g<<-1;
    f.close();
    g.close();
    return 0;
}