Pagini recente » Cod sursa (job #2578735) | Cod sursa (job #1483816) | Cod sursa (job #416961) | Cod sursa (job #2621278) | Cod sursa (job #1700225)
#include <iostream>
#include <fstream>
using namespace std;
ifstream in("fact.in");
ofstream out("fact.out");
#define L 30
long P;
/* PRIMESC UN NR x. AFLU CU CATE ZEROURI SE TERMINA x! i.e. exp LUI 5 ( T. LEGENDRE ) */
int zero(long x)
{
int exp = 0;
while(x >= 5)
{
x /= 5;
exp += x;
}
return exp;
}
int Binary_Search()
{
int i, pas;
i = 0;
pas = 1 << L;
while(pas != 0)
{
if(zero(i + pas) < P) i += pas;
pas /= 2;
}
if(zero(i + 1) > P) return -1;
else
return i + 1;
}
int main()
{
in >> P;
out << Binary_Search();
return 0;
}