Pagini recente » Cod sursa (job #2485035) | Cod sursa (job #2108589) | Cod sursa (job #1983848) | Cod sursa (job #2279588) | Cod sursa (job #470146)
Cod sursa(job #470146)
#include<fstream>
#include<math.h>
using namespace std;
long nr;
int min(long a, long b)
{
if(a<b) return a;
else
return b;
}
int nrOf(int n, int i)
{
int k=0;
while(n%i==0)
{
n=n/i;
k++;
}
return k;
}
int smallest()
{
bool found=false;
long nrof2=0;
long nrof5=0;
long i=0;
while(found==false)
{
if(nr==0)
return 1;
else if(nr==1)
return 0;
else
{
for(int j=1;j<=i;j++)
{
nrof2+=nrOf(j, 2);
nrof5+=nrOf(j, 5);
}
if(min(nrof2, nrof5)==nr)
return i;
i++;
nrof2=0;
nrof5=0;
}
if(i>400000)
return -1;
}
}
int main()
{
ifstream fin;
ofstream fout;
fin.open("fact.in");
fin>>nr;
fin.close();
fout.open("fact.out");
fout<<smallest();
fout.close();
return 0;
}