Cod sursa(job #2510215)

Utilizator Narcis09Grecu Narcis Narcis09 Data 16 decembrie 2019 00:23:41
Problema Factorial Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.37 kb
#include <fstream>
using namespace std;
ifstream cin("fact.in");
ofstream cout("fact.out");
long nrf(long n){
	int r=0, i;
	for (i=5;n/i>=1;i*=5)
		r=r+n/i;
	return r;
}

int main()
{
	int s, d, ind=-1, m, i=1, p;
	cin>>p;
	s=1; d=500000000;
	while (s<=d){
		m=(s+d)/2;
		if (nrf(m)==p){
			ind=m;
			d=m-1;
		}
		if (nrf(m)<p)
			s=m+1;
		else
			d=m-1;
	}	
	cout<<ind;
	
}