Need help in Factorial FCTRL problem

#include <bits/stdc++.h>
using namespace std;

int main()
{
unsigned long long int t,n,res=0,temp;
cin>>t;
while(t–)
{
cin>>n;
res=n/5;
temp=res;
while(temp>5)
{
temp=temp/5;
res+=temp;
}
cout<<res<<"\n";
}
}
/getting correct output for test cases but while submitting getting wrong answer/

if n = 25 , answer should be 6 , your code outputs 5

thanks, i got my error inside while it should be >=.

1 Like

use condition while(temp>1) or while(temp>=5).

you can checkout tutorial video on my channel as well , may be that can help in learning fast
https://www.youtube.com/channel/UC0zvY3yIBQTrSutsV-4yscQ?view_as=subscriber

nice, by the way subscribed your channel.

1 Like

share with your friends if you can , that would be a help.
and thank you .

1 Like

Why can’t I simply find the answer by cout<<(input/5)+(input/25); please explain it to me somebody? Why do I need to divide it if I can find the answer by doing the above method. But if I am trying to do (input/5)+(input/25) I am getting WA.

when n = 125
there are
25 multiples of 5
5 multiples of 25
1 multiple of 125
so the answer should be 31 , but according to your code it will print 30 only.

Oh, So I am not including the multiples of number which are greater than 25? Am I right? @penta_gone :open_mouth:

yes , you got it , you have to check all the multiples of 5 like
5 , then 25 then 125 then 625 and so on till 5^i <= input.

you can check other number theory problems editorial in my number theory playlist.