Cod sursa(job #137378)

Utilizator warcryAlin B warcry Data 17 februarie 2008 11:49:15
Problema Factorial Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.61 kb
#include<fstream>
using namespace std;
ifstream fin("fact.in");
ofstream fout("fact.out");
int main()
{
    int n,p,m,k,sol=0;
    fin>>p;

    if(p==0)
    {
        fout << "1";
        return 0;
    }
        

    for(n=4*p;n<=5*p;++n)
    {
        m=n;
        k=0;
        while(m)
        {
            k+=m/5;
            m/=5;
        }
        if(k==p)
        {
            sol=1;
            fout<<n;
            break;
        }
        else if(k>p)
        {
            sol=0;
            break;
        }
    }
    if(sol==0)
        fout<<"-1";
    return 0;
}