Cod sursa(job #1799748)

Utilizator medicinedoctoralexandru medicinedoctor Data 6 noiembrie 2016 18:51:45
Problema Factorial Scor 40
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.7 kb
#include <fstream>

using namespace std;

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

void xf(int x, int &c) // x = (5 ^ c) * ...
{
    c=0;
    while (x % 5 == 0)
    {
        c++;
        x=x/5;
    }
}

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=5; zr<=nz; x+=5)
    {
        xf(x,fc);
        if (zr+fc>nz)
        {
            cout << -1;
            zr=nz+1;
        }
        else
            if (zr+fc==nz)
            {
                cout << x ;
                zr = nz + 1;
            }
            else zr+=fc;
    }
}