Cod sursa(job #1306220)

Utilizator mihai9913Blaga Mihai mihai9913 Data 30 decembrie 2014 18:20:01
Problema Factorial Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.95 kb
#include <fstream>
using namespace std;
ifstream f("fact.in");
ofstream g("fact.out");
int n, rez, y;
int st, dr, mij;
bool ok = false;

int N5(int x)
{   int cnt=0;
    while(x>=1)
    {
        x/=5;
        cnt+=x;
    }
    return cnt;
}

int main()
{
    f>>n;
    if(n==0 )
        g<<1;
    else
    {
        st=0;
        dr=(1<<31)-1;
        while(st<=dr && ok==false)
        {
            mij=(st+dr)/2;
            if(N5(mij)==n)
            {
                ok=true;
                continue;
            }
            if(N5(mij)>n)
            {
                dr=mij-1;
                continue;
            }
            if(N5(mij)<n)
            {
                st=mij+1;
                continue;
            }
        }
        if(ok==false)
            g<<-1;
        else
        {
            while(mij%5) mij--;
            g << mij;
        }
    }

    g.close();

    return 0;
}