Cod sursa(job #2698419)

Utilizator GheorgheBBalamatiuc Gheorghe GheorgheB Data 22 ianuarie 2021 00:55:00
Problema Factorial Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.42 kb
#include <iostream>
#include <fstream>
using namespace std;
int a[1000000000];
ifstream fin("fact.in");
ofstream fout("fact.out");
int main(){
	int p, k; fin>>p; 
	int st=1, dr=1000000000, poz=0, m;
	while(st<=dr && poz==0){
		m=(st+dr)/2;
		k=0;
		for(int i=5;m/i>=1;i*=5)
			k+=m/i;
		if(k==p)
			poz=m;
		else
			if(p>k)
				st=m+1;
			else
				dr=m-1;
	}
	if(poz!=0)
		fout<<poz;
	else
		fout<<"-1";
}