Cod sursa(job #849641)

Utilizator sinio1Stirbat Luca sinio1 Data 7 ianuarie 2013 14:20:48
Problema Factorial Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.56 kb
#include<fstream>
using namespace std;
ifstream f("fact.in");
ofstream g("fact.out");
int fct (int x)
{
    int putere=0,k=5;
    while (x/k>=1)
    {
        putere=x/k+putere;
        k=k*5;
    }
    return putere;
}
int main ()
{
int p,n,x1,x2,pp,y;
f>>p;
f>>n;
x1=1;
x2=1000000000;
pp=0;
while (x1<=x2&&pp==0)
{
	n=(x1+x2)/2;
	y=fct(n);
	if (y==p)
	{
		pp=1;
		n=n-n%5;
	}
	else
		if (y<p)
            x1=n+1;
	else
		x2=n-1;
}
if (pp==0)
    g<<"-1"<<"\n";
else
if (p==0)
    g<<1<<"\n";
else
if (pp==1)
    g<<n<<"\n";
}