Cod sursa(job #1385311)

Utilizator GinguIonutGinguIonut GinguIonut Data 11 martie 2015 21:04:51
Problema Factorial Scor 50
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.54 kb
#include <fstream>
using namespace std;
ifstream fin("fact.in");
ofstream fout("fact.out");
long int i,j,p,vect[100000001],sol;
int main()
{
fin>>p;
if(p==0)
    fout<<1;
else
{
    while(vect[i]<=p)
    {
        if(vect[i]==p)
        {
            sol=i;
            break;
        }
        i++;
        vect[i]=vect[i-1]+1;
        j=i;
        while(j%5==0&&j!=0)
        {
            j/=5;
            vect[i]++;
        }
    }
    if(sol!=0)
        fout<<i*5;
    else
        fout<<-1;
}

    return 0;
}