Pagini recente » Cod sursa (job #2032377) | Cod sursa (job #2692788) | Cod sursa (job #2174063) | Cod sursa (job #2117106) | Cod sursa (job #1169412)
/******************************************************************************************
* .--. *
* ::\`--._,'.::.`._.--'/:: @author Ana M. Mihut @course InfoArena Tryout *
* ::::. ` __::__ ' .::::: @alias LT-Kerrigan @date 10.04.2014 *
* ::::::-:.`'..`'.:-:::::: @link http://infoarena.ro/problema/fact *
* ::::::::\ `--' /:::::::: @detail *
* *
*******************************************************************************************/
#include <iostream>
#include <fstream>
int ChkZero(int n, int d, int divBy){
int tmp = n / divBy;
return ((tmp != 0) ? (ChkZero(n, d + tmp, divBy *5)) : d);
}
int main(){
int p, mid;
int lhs = 1;
std::ifstream in("fact.in");
std::ofstream out("fact.out");
in >> p;
int rhs = 5 * p;
while (lhs <= rhs){
mid = lhs + (rhs - lhs) / 2;
(ChkZero(mid,0,5) < p) ? (lhs = mid + 1) : (rhs = mid - 1);
}
(ChkZero(lhs, 0, 5) == p) ? (out << lhs) : (out << "-1");
return 0;
}