Pagini recente » Istoria paginii runda/ccex2015-11-12/clasament | Istoria paginii runda/test12 | Monitorul de evaluare | The Cat | Cod sursa (job #1170084)
// 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;
}