Cod sursa(job #2704190)

Utilizator tomaionutIDorando tomaionut Data 9 februarie 2021 21:58:38
Problema Factorial Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.57 kb
#include <bits/stdc++.h>
using namespace std;
ifstream fin("fact.in");
ofstream fout("fact.out");
int p;
int Check(int x)
{
	int q = 5, cnt = 0;
	while (q <= x)
	{
		cnt += (x / q);
		q *= 5;
	}
	return cnt;
}
int main()
{	
	int st,dr,mij,x,sol=-1;
	fin >> p;
	if (p == 0) fout << "1\n";
	else
	{
		st = 1;
		dr = 1e9;
		while (st <= dr)
		{
			mij = (st + dr) / 2;
			x = Check(mij);
			if (x == p)
			{
				sol = mij;
				dr = mij - 1;
			}
			else if (x > p) dr = mij - 1;
			else st = mij + 1;
		}
		fout << sol;
	}



	return 0;
}