Pagini recente » Cod sursa (job #1165673) | Cod sursa (job #934697) | Monitorul de evaluare | Cod sursa (job #829223) | Cod sursa (job #2907386)
// Infoarena.cpp : This file contains the 'main' function. Program execution begins and ends there.
#include <iostream>
#include <fstream>
#include <math.h>
int main()
{
//std::cout << "Executing..." << std::endl;
std::ifstream in;
in.open("fact.in");
std::ofstream out;
out.open("fact.out");
int target = 0;
in >> target;
in.close();
if (target < 0) {
out << -1;
out.close();
return 0;
}
if (target == 0) {
out << 1;
out.close();
return 0;
}
int n5 = 0;
int n10 = 0;
long int index = 5;
do {
if (n10 + n5 > target) {
out << -1;
out.close();
return 0;
}
long int current = index;
double l10 = log10(current);
if (l10 == floor(l10)) {
n10 += l10;
current = l10;
}
double log5 = log2(current) / log2(5);
if (log5 == floor(log5)) {
n5 += log5;
}
else if (current % 5 == 0) {
n5 += 1;
}
index += 5;
} while (n10 + n5 != target);
out << index - 5;
out.close();
return 0;
}