I was trying to find the number of zeroes in a factorial of a number. The time limit was 2 sec. Max number of test cases being 100000
my code is as follows
#include<iostream>
#include<cstdio>
int five(int number);
int two(int number);
using namespace std;
main()
{
int num;
int t,i;
int no_five=0,no_two=0;
scanf("%d",&t);
for(i=0;i<t;i++)
{
scanf("%d",&num);
for(int j=1;j<=num;j++)
{
no_five+=five(j);
no_two+=two(j);
}
if(no_five>no_two)
printf("%d\n",no_two);
else
printf("%d\n",no_five);
no_five=0;
no_two=0;
}
}
int five(int num)
{
int i=0;
while(num%5==0)
{
i++;
num/=5;
}
return i;
}
int two(int num)
{
int i=0;
while(num%2==0)
{
i++;
num/=2;
}
return i;
}
Please tell me how to optimize my approach