Cod sursa(job #1650130)

Utilizator Tester1000Oinaru Razvan Tester1000 Data 11 martie 2016 16:44:40
Problema Factorial Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.63 kb
#include <iostream>
#include <fstream>
using namespace std;
ifstream f("fact.in");
ofstream g("fact.out");
int main()
{
    int P,i,ok=0,s,j;
    f>>P;
    if(P==0)
        g<<"1";
    else if(P<5)
        g<<P*5;
    if(P>=5)
    {
        i=P*4;
        while(ok==0)
        {
            s=0;
            for(j=5; j<=i; j=j*5)
                s=s+i/j;
            if(s>P)
            {
                g<<"-1";
                ok=1;
            }
            else if (s==P)
            {
                g<<i/5*5;
                ok=1;
            }
            i=i+5;
        }
    }

    return 0;
}