Cod sursa(job #2427982)
Utilizator | Data | 3 iunie 2019 10:58:35 | |
---|---|---|---|
Problema | Factorial | Scor | 100 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva de probleme | Marime | 0.61 kb |
#include <iostream>
#include <fstream>
using namespace std;
const int VMAX=500000000;
int nr_zero(int n){
int nr=0;
while(n>0)
{
nr+=n/5;
n/=5;
}
return nr;
}
int main()
{
fstream fin("fact.in");
ofstream fout("fact.out");
int p;
fin >> p;
int st=1;
int dr=VMAX;
while(st<dr)
{
int m=(st+dr)/2;
if(nr_zero(m)>=p)
{
dr=m;
}
else
{
st=m+1;
}
}
if (nr_zero(st) != p)
{
st = -1;
}
fout<<st;
fin.close();
fout.close();
return 0;
}