Cod sursa(job #923340)

Utilizator SagunistuStrimbu Alexandru Sagunistu Data 23 martie 2013 13:38:12
Problema Factorial Scor 60
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.63 kb
#include <iostream>
#include <fstream>

using namespace std;

int main()
{ifstream fin("fact.in");
ofstream fout("fact.out");
int p,i,j,ok,k,nr,c;
fin>>p;
if(p==0)
    fout<<"1";
else
{j=0;
i=0;
ok=1;
k=0;
while(1)
    {i++;
     k++;
     j+=5;
     nr=k;
     if(k%5==0)
        {c=0;
         while(1)
            {if(nr%5)
                break;
             nr/=5;
             c++;
            }
         i=i+c;
        }
     if(i==p)
        break;
     else
     if(i>p)
        {
         ok=0;
         break;
        }
    }
if(ok==0)
    fout<<"-1";
else
    fout<<j;
}
    return 0;
}