Cod sursa(job #1170084)

Utilizator adi.adnan10Adi Adnan adi.adnan10 Data 12 aprilie 2014 17:28:34
Problema Factorial Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.7 kb
// IAfactorial.cpp : Defines the entry point for the console application.
//
#include<stdio.h>
using namespace std;

inline int min(int x, int y)
{
	return (x < y) ? x : y;
}

int five(int x)
{
	int y = x,k=0;
	while (!(y % 5))
	{
		y = y / 5;
		k++;
	}
	return k;
}
int two(int x)
{
	int y = x, k = 0;
	while (!(y%2))
	{
		y = y / 2;
		k++;
	}
	return k;
}
int main()
{
	FILE *in, *out;
	in = fopen("fact.in","r");
	out = fopen("fact.out", "w");
	int n,twos=0,fives=0;
	fscanf(in,"%d",&n);
	while (n > 0)
	{
		twos += two(n);
		fives += five(n);
		n--;
	}
	if (!min(twos, fives))
		fprintf(out, "%d", -1);
	else
	fprintf(out,"%d",min(twos, fives));
	return 0;
}