Cod sursa(job #1358726)

Utilizator StefanutzzKis Stefan Marian Stefanutzz Data 24 februarie 2015 19:25:35
Problema Factorial Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.65 kb
#include <fstream>
ifstream cin("fact.in");
ofstream cout("fact.out");
using namespace std;

int fct(int x)
{
    int a=5,rez=0;
    while (x/a)
    {
        rez=rez+x/a;
        a=a*5;
    }
    return rez;
}

int main()
{
    int p,valoare;
    cin>>p;
    if ( p==0 )
        cout<<1;
    else
    {
        int min=1,max=NMax,mid;
        bool ok=false;
        while(min<=max && !ok)
            valoare=fct(mid);
        if (valoare<p) min=mid+1;
        else if (valoare>p) max=mid-1;
        else ok=true;
    }
    if ( ok )
    {
        while (mid%5) mid--;
        cout<<mid;
    }
    else cout<<-1;
    return 0;
}