Cod sursa(job #1948296)

Utilizator SmLighteAvrigeanu Theodor SmLighte Data 31 martie 2017 22:54:24
Problema Factorial Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.5 kb
#include <iostream>
#include <fstream>
using namespace std;
ifstream f("fact.in");
ofstream g("fact.out");

int test(int x)
{
	int z = 5, t = 0;
	while (x / z)
	{
		t = t + x / z;
		z = z * 5;
	}
	return t;
}

int main()
{
	int p, l = 1, r = 1000000000, q, sol = -1, x;
	f >> p;
	while (l <= r)
	{
		q = (l + r) / 2;
		x = test(q);
		if (x<p)
			l = q + 1;
		else
			if (x>p)
				r = q - 1;
			else
			{
				sol = q;
				r = q - 1;
			}
	}
	g << sol << "\n";
	return 0;
}