Cod sursa(job #844139)

Utilizator hiticas_abelhiticasabel hiticas_abel Data 28 decembrie 2012 20:56:53
Problema Factorial Scor 100
Compilator cpp Status done
Runda 23dezile_2 Marime 0.45 kb
#include <fstream>
using namespace std;
ifstream f("fact.in");
ofstream g("fact.out");
int main() 
{
    int k,p,n,pow;
    f>>p;
    n = 4*p,k=0;pow=5;
    while(n/pow)
     k += n/pow, pow *= 5;
    n = 5*(n/5+1);
    do {
        pow = 5, k = 0;
        while(n/pow) k += n/pow, pow *= 5;
        n += 5;
    } while(k < p);
    n -= 5;
    if(p == 0) g<<1;
    else {
        if(k == p) g<<n;
        else g<<-1;
    }
    return 0;
}