Cod sursa(job #1799856)

Utilizator medicinedoctoralexandru medicinedoctor Data 6 noiembrie 2016 21:44:02
Problema Factorial Scor 60
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.72 kb
#include <fstream>

using namespace std;

ifstream cin("fact.in");
ofstream cout("fact.out");

inline int xf(int x) // x = (5 ^ c) * ...
{
    int c=0;
    while (x % 5 == 0)
    {
        c++;
        x=x/5;
    }
    return c;
}

main()
{
    int nz,zr=0,fc=0,x; // nz - numarul de zerouri, fc - x! = 5^fc * ?, zr - zerourile lui x factorial
    cin >> nz;
    if (nz==0) cout << 1;
    else
    for (x=1; zr<=nz; x++)
    {
        fc=xf(x)+1;
        if (zr+fc>nz)
        {
            cout << -1;
            zr=nz+1;
        }
        else
            if (zr+fc==nz)
            {
                cout << 5*x ;
                zr = nz + 1;
            }
            else zr+=fc;
    }
}