Pagini recente » Cod sursa (job #456728) | Cod sursa (job #2038595) | Cod sursa (job #1056029) | Cod sursa (job #382613) | Cod sursa (job #1012568)
#include<fstream>
#include<cmath>
#include<iostream>
//#include<climits>
using namespace std;
int calc(int);
int main(){
ifstream inFile("fact.in");
ofstream outFile;
outFile.open("fact.out");
long p;
inFile>>p;
// int i;
// outFile<<LONG_MAX<<"\n";
// for(i=1;calc(i)<p;i++);
if(p==0){
outFile<<1;
return 0;
}
long a=0, b=400000018;
long k=(a+b)/2;
long aux=calc(k);
while(aux!=p){
if(aux>p) b=k;
else if(aux<p) a=k;
else{
break;
}
k=(a+b)/2;
aux=calc(k);
if(b-1==a && calc(k)!=p){
outFile<<-1;
return 0;
}
}
if(k%5==0) k+=0;
else while(k%5!=0) k--;
outFile<<k;
}
int calc(int n){ //Calculam exponentul lui 5 in n!
int expFive=0; //expTwo=0;
int q=n/pow(5,1);
for(int i=1;q>0;i++){
expFive+=q;
q=n/pow(5,i+1);
}
/*
for(int i=1;n/pow(2,i)>0;i++) expTwo+=n/pow(2,i);
int k;
k=(expTwo>expFive)?expFive:expTwo;
*/
return expFive;
}