Pagini recente » Cod sursa (job #2220803) | Cod sursa (job #757202) | Cod sursa (job #304609) | Cod sursa (job #757767) | Cod sursa (job #705821)
Cod sursa(job #705821)
#include<fstream>
#include<math.h>
#include<limits.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){
//out<<i<<" "<<j<<endl;
if(j<i){
out<<-1;
return 0;
}
unsigned x=(i+j)/2;
if(nr_zero_fact(x)==g_p){
while(nr_zero_fact(x-1) == nr_zero_fact(x)){
x--;
}
out<<x;
return 0;
}else if(nr_zero_fact(x)>g_p){
return cautare(i,x-1);
}else if(nr_zero_fact(x)<g_p){
return cautare(x+1,j);
}else{
out<<-1;
return 0;
}
}
int main(){
in>>g_p;
if(g_p==0){
out<<-1;
return 0;
}
cautare(1,INT_MAX);
return 0;
}