Cod sursa(job #1697348)

Utilizator andrew_assassin789Andrei Manea andrew_assassin789 Data 1 mai 2016 18:30:00
Problema Factorial Scor 50
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.52 kb
#include <fstream>
#include <algorithm>
using namespace std;
int main()
{
    ifstream f("fact.in");
    ofstream g("fact.out");
    unsigned int i,x,p,n0=0,ant;
    f>>p;
    if (p==0) g<<"1\n";
    else
    {
        for (i=5;n0<p;i+=5)
        {
            x=i;ant=n0;
            while (x%5==0)
                x/=5,n0++;
        }
        if (n0==p) g<<i-5<<'\n';
        else
            if (ant==p) g<<i-10<<'\n';
            else g<<"-1\n";
    }
    f.close();
    g.close();
    return 0;
}