Cod sursa(job #1003930)

Utilizator acomAndrei Comaneci acom Data 1 octombrie 2013 19:41:35
Problema Factorial Scor 60
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.5 kb
#include<fstream>
using namespace std;
ifstream f("fact.in");
ofstream g("fact.out");
int n;
int term(int k)
{
    int r=5,rez=0;
    while (k/r)
        {
            rez+=k/r;
            r*=5;
        }
    return rez;
}
int main()
{
    int m,st=1,dr=100000000;
    f>>n;
    while (st<=dr)
        {
            m=(st+dr)/2;
            if (term(m)>=n) dr=m-1;
            else st=m+1;
        }
    if (term(dr+1)==n)
        g<<dr+1<<'\n';
    else g<<"-1\n";
    return 0;
}