Cod sursa(job #915985)

Utilizator robertstrecheStreche Robert robertstreche Data 15 martie 2013 17:49:38
Problema Factorial Scor 15
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.4 kb
#include <iostream>
#include <fstream>
using namespace std;
ifstream f("fact.in");
ofstream g("fact.out");
int p,x=1,nr=0,c;
int main()
{
    f>>p;
    f.close();
    while (nr<p)
    {
        x*=5;
        nr=2*nr+x/5;
    }
    while (nr>p)
    {
        c=x;
        while (c%5==0){nr--;c/=5;}
        x-=5;
    }
    if (nr==p)g<<x;
    else g<<"-1";
    g.close();
    return 0;
}