Cod sursa(job #1889246)

Utilizator mesbotMeszaros Botond mesbot Data 22 februarie 2017 17:20:46
Problema Factorial Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.42 kb
#include <fstream>

long int p, n, c;

long int ft(long int num)
{
    c = 0;
    while(num != 0)
        num /= 5, c += num;

    return c;
}

int main()
{
    std::ifstream f("fact.in");
    std::ofstream g("fact.out");
    f>>p;

    if(p == 0)
        g<<1;
    else
    {
        n = 4*p;
        for(; ft(n) < p;) n++;
        if(ft(n) > p) g<<-1;
        else g<<n;
    }

    return 0;
}