Pagini recente » Istoria paginii utilizator/anca.bragau | Cod sursa (job #2850091) | bob | Cod sursa (job #798545) | Cod sursa (job #2266829)
#include <iostream>
#include <fstream>
using namespace std;
int nrzero (int x)
{
int nr=0;
while (x>=5)
{
nr+=x/5;
x/=5;
}
return nr;
}
int fact (int P)
{
int r=0, pas=1<<28;
while (pas!=0)
{
if (nrzero (r+pas)<P)
r+=pas;
pas/=2;
}
return 1+r;
}
ifstream in("fact.in");
ofstream out("fact.out");
int main()
{
int a,P;
in>>P;
a= fact (P);
if (nrzero (a)!=P)
out<< -1;
else
out<< a;
in.close ();
out.close ();
return 0;
}