Pagini recente » Cod sursa (job #1905563) | Cod sursa (job #2502526) | Cod sursa (job #2377081) | Cod sursa (job #2127827) | Cod sursa (job #485484)
Cod sursa(job #485484)
/*
* Main.c
*
* Created on: 18.09.2010
* Author: bugkiller
*/
#include <iostream>
#include <fstream>
using namespace std;
/**
* Numarul de zerouri pentru n!
*/
int numara ( int n ){
int old = n;
int ret = 0;
while ( n>0){
ret+=n/5;
n=n/5;
}
//cout <<"Numara" <<old <<" " <<ret << endl;
return ret;
}
int main()
{
int a;
ifstream input ("fact.in");
ofstream f ("fact.out");
input >> a;
//cin >> a;
int left = 0;
int right = 1<<31-1;
int pos=-1;
//cout << right;
while ( left!=right){
int m = (left+right)/2;
int rez = numara(m);
if ( rez==a ) {
pos = m;
break;
} else{
if ( rez>a){
// cautam in stanga
right=m-1;
} else{
// cautam in dreapta :)
left = m+1;
}
}
}
while ( numara(pos-1)==a){
pos--;
}
cout << pos;
f << pos<< endl;
input.close();
f.flush();
f.close();
return 0;
}