Cod sursa(job #1012825)

Utilizator CarhatEmanuelCarhat Emanuel CarhatEmanuel Data 19 octombrie 2013 18:10:56
Problema Factorial Scor 100
Compilator cpp Status done
Runda micuti1 Marime 0.48 kb
#include <fstream>
using namespace std;
ifstream f("fact.in");
ofstream g("fact.out");
int main()
{
    int k,p,n,putere;
    f>>p;
    n = 4*p,k=0;putere=5;
    while(n/putere)
     k += n/putere, putere *= 5;
    n = 5*(n/5+1);
    do {
        putere= 5, k = 0;
        while(n/putere) k += n/putere, putere *= 5;
        n += 5;
    } while(k < p);
    n -= 5;
    if(p == 0) g<<1;
    else {
        if(k == p) g<<n;
        else g<<-1;
    }
    return 0;
}