Pagini recente » Rating Mihnea Morosan (Mmoro2006) | Cod sursa (job #2669) | Cod sursa (job #1721040) | Cod sursa (job #1054787) | Cod sursa (job #3044)
Cod sursa(job #3044)
#include <fstream.h>
long desc(long aux);
long nr,min=0,max=100000000,med,val;
int sw=1;
int main()
{
ifstream fin("fact.in");
fin>>nr;
fin.close();
ofstream fout("fact.out");
if(nr==0)
fout<<'1';
else
{
while(sw)
{
med=(min+max)/2-((min+max)/2)%5;
val=desc(med);
if(val==nr)
{
sw=0;
fout<<med;
fout.close();
return 0;
}
else
if(val>nr)
max=med-5;
else
min=med+5;
}
}
fout<<"-1";
fout.close();
return 0;
}
long desc(long aux)
{
long y=0,y1=aux;
int sw=1;
while(sw)
{
y1=y1/5;
y=y+y1;
if(y1==0)
sw=0;
}
return y;
}