Pagini recente » Cod sursa (job #1812614) | Cod sursa (job #1316101) | Cod sursa (job #1653870) | Cod sursa (job #2432958) | Cod sursa (job #1004535)
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cstring>
using namespace std;
ifstream in("fact.in");
ofstream out("fact.out");
//int NMAX = 1000000000;
int f( int x ){
int rez = 0;
int a = 5;
while(1){
rez += x/a;
if( x/a == 0 )
break;
a *= 5;
}
return rez;
}
int main(){
int p;
in >> p;
int left = 1, right = 1000000000, mid, temp, rez = -1;
cout<< f(1000) <<endl;
while( left <= right ){
mid = left + (right-left)/2;
temp = f(mid);
if( temp == p ){
rez = mid;
break;
}
else if( temp < p )
left = mid + 1;
else
right = mid - 1;
}
if(rez != -1)
while( rez%5 != 0 ) rez--;
if(p==0)
rez = 1;
out<<rez<<endl;
return 0;
}