Cod sursa(job #2378633)

Utilizator Razvan11Rus Razvan Constantin Razvan11 Data 12 martie 2019 15:01:10
Problema Factorial Scor 95
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.35 kb
#include <fstream>
using namespace std;
ifstream f("fact.in");
ofstream g("fact.out");

int main(){
long long st=0,dr=1e9,mid,s=0,P,sol=-1;
f>>P;
while(st<=dr){
	s=0;
	mid=(st+dr)/2;
	for(long long i=5; i<=mid; i*=5){
		s=s+mid/i;
	}
	if(s>P){
		dr=mid-1;
	}
	else{
		if(s<P){
		st=mid+1;
		}
		else{
			dr=mid-1;
			sol=mid;
			}
	}
}
	g<<sol;
	return 0;
}