Pagini recente » Cod sursa (job #1915648) | Cod sursa (job #1802952) | Cod sursa (job #2806376) | Cod sursa (job #1387330) | Cod sursa (job #3185619)
#include <iostream>
#include <fstream>
using namespace std;
ofstream fout ("fact.out");
ifstream fin ("fact.in");
int main()
{
int i, p, chestie=5,s=0,l=1,r=2e9,mij=0,poz=0;
fin >> p;
poz=0;
l=1;
r=2e9;
while (l<=r)
{
mij=(l+r)/2;
s=0;
chestie=5;
while (chestie<=mij)
{
s=s+mij/chestie;
chestie=chestie*5;
}
if (s<p)
{
l=mij+1;
}
else
{
poz=mij;
r=mij-1;
}
}
s=0;
chestie=5;
while (chestie<=poz)
{
s=s+poz/chestie;
chestie=chestie*5;
}
if (s!=p)
{
fout << "-1";
}
else
{
fout << poz;
}
return 0;
}