Cod sursa(job #1804883)

Utilizator Andrei.CosteaAndrei Costea Andrei.Costea Data 13 noiembrie 2016 10:28:31
Problema Factorial Scor 20
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.69 kb
#include <fstream>
#include <cmath>

using namespace std;

long long c,p,aux,k,i;
float st,dr,n;

ifstream f("fact.in");
ofstream g("fact.out");

int main()
{
    f>>p;
    n=0;
    if (p==0)
    {
        g<<1;
        return 0;
    }

    st=0;
    dr=0;
    i=0;
    while (p>dr)
    {
        i++;
        st=dr;
        dr=dr+pow(5,i)-1;
    }
    c=st;
    n=pow(5,i)-5;
    while (c<p)
    {
        n=n+5;
        k=1;
        aux=n;
        while (aux)
        {
            aux=aux/5;
            if (aux%5==0) k++;
            else break;
        }
        c=c+k;
    }
    if (c>p) n=-1;
    g<<n;
    f.close();
    g.close();
    return 0;
}