Pagini recente » Cod sursa (job #240799) | Cod sursa (job #705809)
Cod sursa(job #705809)
#include<fstream>
#include<math.h>
using namespace std;
unsigned g_p;
ifstream in("fact.in");
ofstream out("fact.out");
unsigned nr_zero_fact(unsigned n){
unsigned q=1,c=1,s=0;
while(q!=0){
q=(unsigned)floor((double)n/pow((double)5,(double)c));
s+=q;
c++;
}
return s;
}
unsigned cautare(unsigned i, unsigned j){
unsigned x=(i+j)/2;
if(nr_zero_fact(x)==g_p){
while(nr_zero_fact(x-1) == nr_zero_fact(x)){
x--;
}
return x;
}else if(nr_zero_fact(x)>g_p){
return cautare(i,x);
}else if(nr_zero_fact(x)<g_p){
return cautare(x,j);
}else{
out<<"ERROR: out of range";
exit(0);
}
}
int main(){
in>>g_p;
out<<cautare(1,INT_MAX);
return 0;
}