Pagini recente » Cod sursa (job #2848177) | Cod sursa (job #1315153) | Cod sursa (job #3032245) | Cod sursa (job #3143567) | Cod sursa (job #1044923)
#include<stdio.h>
int solutie(int n)
{
int x=1,sol=0;
while(x<=n)
{
x=x*5;
sol=sol+n/x;
}
return sol;
}
int main()
{
int a=-1,m,x,y,p,ok=0;
FILE *f=fopen("fact.in","r");
FILE *g=fopen("fact.out","w");
fscanf(f,"%d",&p);
if(p==0)
fprintf(g,"1");
else
{
x=5; y=500000000;
while(x<=y)
{
m=(x+y)/2;
if(y==(x+1))
{
if(solutie(x)==p)
{
ok=1;
a=x;
}
if(solutie(y)==p)
{
ok=1;
a=y;
}
x=y+1;
}
if(solutie(m)<p&&x<=y)
x=m;
if(solutie(m)>p&&x<=y)
y=m;
if(solutie(m)==p&&x<=y)
{
ok=1;
a=m;
x=y+1;
}
}
if(ok==1)
while(a%5!=0)
a--;
fprintf(g,"%d",a);
}
}