Cod sursa(job #694341)

Utilizator sleepaholicNeculaescu Theodor sleepaholic Data 27 februarie 2012 20:01:32
Problema Factorial Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.44 kb
#include<fstream>
using namespace std;
ifstream f("fact.in");
ofstream g("fact.out");

int fact(int n, int p)
{
int a=0;
while (n)
{
a+=n/5;
n=n/5;
}
if(a==p)
return 1;
else
if (a<p)
return 0;
if (a>p)
return -1;
}
int main()
{
int i=1,p,n;
f>>p;
if(p)
{
n=(4*p-((4*p)&5));
while (i)
{
if(fact(n,p)==1)
{g<<n-n%5; i=0;}
if(fact(n,p)==-1)
{g<<-1; i=0;}
if(fact(n,p)==0)
n+=5;
}
}
else    g<<1;
return 0;
}