Cod sursa(job #2210331)

Utilizator Fantastic_Mantudor voicu Fantastic_Man Data 6 iunie 2018 11:55:07
Problema Factorial Scor 90
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.54 kb
#include <iostream>
#include <cstdio>
using namespace std;
int zero(int n) {
	int p=5,s=0;
	while(n/p!=0) {
		s+=n/p;
		p*=5;
	}
	return s;
}
int main()
{
	freopen("fact.in","r",stdin);
	freopen("fact.out","w",stdout);
    int n,st,dr,mij,elem=-1;
    scanf("%d",&n);
    if(n==0) {
		cout<<1;
		return 0;
	}
    st=0;
    dr=5*n;
    while(st<=dr) {
		mij=(st+dr)/2;
		if(zero(mij)>n)
			dr=mij-1;
		else {
			elem=mij;
			st=mij+1;
		}
    }
    if(elem==-1)
		cout<<elem;
	else
		cout<<elem/5*5;


    return 0;
}