Pagini recente » Cod sursa (job #2112892) | Cod sursa (job #1628029) | Cod sursa (job #1167632) | Cod sursa (job #1023961) | Cod sursa (job #705816)
Cod sursa(job #705816)
#include<fstream>
#include<math.h>
#include<stdlib.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;
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(j==i+1){
out<<-1;
return 0;
}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;
if(g_p==1 || g_p==0){
out<<-1;
return 0;
}
cautare(1,INT_MAX);
return 0;
}