Cod sursa(job #1253868)

Utilizator costty94Duica Costinel costty94 Data 1 noiembrie 2014 21:54:58
Problema Factorial Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.71 kb
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <limits.h>

long long cifra(long long int n)
{
	long long int s, p = 5, i;
	s = 0;
	while(p <= n)
	{
		s += n / p;
		p = p * 5;
	}
	return s;
}
long long int n, st, dr, mij, ok;

int main()
{
	freopen("fact.in", "r", stdin);
	freopen("fact.out", "w", stdout);

	scanf("%lld", &n);
	st = 1;
	dr = 1000000000;
	ok = 0;
	if(n == 0)
	{
		printf("1");
		return 0;
	}
	while(st <= dr && !ok)
	{
		mij = (st + dr) / 2;
		if(cifra(mij) > n)
			dr = mij - 1;
		else if(cifra(mij) < n)
			st = mij + 1;
		else
		{
			ok = 1;
			
		}
	}
	if(ok == 1)
		printf("%lld", mij - mij % 5);
	else
		printf("-1");
	return 0;

}