Cod sursa(job #194457)

Utilizator cristideluClaudiu Antonovici cristidelu Data 10 iunie 2008 20:37:00
Problema Factorial Scor 10
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.48 kb
#include <iostream.h>
#include <fstream.h>
ifstream f;
ofstream g;

unsigned long fact(int x)
{int i;
unsigned long p=1;
for (i=1;i<=x;i++)
p*=i;
return p;}

int nrc(unsigned long x)
{int n=0;
while (x%10==0)
{n++;
x/=10;}
return n;}

int main()
{int p,n=1,ok=1;
f.open("fact.in");
g.open("fact.out");
f>>p;
if (p==0)
g<<1;
else
{while (nrc(fact(n))!=p && ok)
{if (nrc(fact(n))>p)
ok=0;
n++;}
if (ok)
g<<n;
else
g<<-1;}
f.close();
g.close();
return 0;}