Cod sursa(job #992910)

Utilizator skyper96skyper skyper96 Data 2 septembrie 2013 18:59:23
Problema Factorial Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.84 kb
#include <iostream>
#include <fstream>

using namespace std;

int main()
{
    ifstream f("fact.in");
    ofstream g("fact.out");
    int i,p,n,ok,j,k,ok2,cont;
    f>>p;
    if(p==1)
        g<<"0";
    if(p>1)
    {
        ok=0;
        i=0;
        while(ok==0)
        {
            n=1;
            i++;
            for(j=1;j<=i;++j)
            {
                n=n*j;
            }
            ok2=1;
            cont=0;
            while(ok2)
            {
                if(n%10!=0)
                    ok2=0;
                if(n%10==0&&ok2==1)
                {
                    cont++;
                    n=n/10;
                }
            }
            if(cont==p)
                ok=1;
        }
        if(ok==1)
            g<<i;
        if(ok==0)
            g<<"-1";
    }
    return 0;
}