Cod sursa(job #1170081)

Utilizator adi.adnan10Adi Adnan adi.adnan10 Data 12 aprilie 2014 17:25:35
Problema Factorial Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.65 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("factorial.in","r");
	out = fopen("factorial.out", "w");
	int n,twos=0,fives=0;
	fscanf(in,"%d",&n);
	while (n > 0)
	{
		twos += two(n);
		fives += five(n);
		n--;
	}
	fprintf(out,"%d",min(twos, fives));
	return 0;
}