Pagini recente » Cod sursa (job #2369760) | Cod sursa (job #2564598) | Cod sursa (job #2730830) | Cod sursa (job #875858) | Cod sursa (job #2068335)
#include <fstream>
using namespace std;
ifstream in ("fact.in");
ofstream out ("fact.out");
long long p;
bool putere (int a,int b)
{
long long s=0;
while(a)
{
a=a/5;
s+=a;
}
if(s<b)
return true;
return false;
}
bool puter (int a,int b)
{
long long s=0;
while(a)
{
a=a/5;
s+=a;
}
if(s==b)
return true;
return false;
}
int main()
{
long long k=0,pas=1<<30;
in>>p;
while(pas)
{
if(putere(k+pas,p))
k+=pas;
pas/=2;
}
if(puter(k+1,p))
out<<k+1;
else
out<<-1;
return 0;
}