Since we have to stop below 1. (Read the editorial)
And previously you are doing > 1(Means excluding 1)
Even >=1 also works here (that’s why maybe testcase with 5 fails previously)
I get output as per sample input given on problem statement but submission says solution is wrong, please help pointing mistake with the solution
using namespace std;
int main()
{
int intinput;
cin >> intinput;
int zeros=0;
do
{
intinput = intinput/5;
zeros = intinput+zeros;
} while (intinput != 0);
cout << zeros;
}
Can someone kindly explain what’s wrong in this code?
#include<stdio.h>
int main()
{
int t,n,i,j;
scanf("%d",&t);
for(i=0;i<t;i++)
{
scanf("%d",&n);
int c=0;
for(j=5;n/j>0;j*=5)
{
c+=n/j;
}
printf("%d",c);
}
return 0;
}
I cant understand the problem. what we have to find here .can someone explain in an easy language.
I cant understand the problem. what we have to find here .can someone explain in an easy language.
I cant understand the problem. what we have to find here .can someone explain in an easy language. why taking 25 , 125 … if they are already multiple of 5
t=int(input())
for i in range(t):
b=0
i=1
num=int(input())
while i>0:
if num/(5i)>=1:
b+=num//(5i)
i+=1
else:
break
print(b)
I like how they put this in the EASY category but it’s really not
HEY CAN SOMEONE TELL WHY MY CODE IS NOT WORKING , i m getting the right sample output though
#include <stdio.h>
long int gi(float n);
unsigned long int no5(unsigned long int x);
int main(void) {
unsigned int t;
unsigned long int k;
scanf("%d",&t);
while(t–)
{
scanf("%lu “,&k);
printf(”%lu \n",no5(k));
}
return 0;
}
long int gi(float n){
unsigned long x;
x=(unsigned long)n;
return x;
}
unsigned long int no5(unsigned long int x){
unsigned long int z;
int cnt=0;
z=x;
while(1)
{
z=z/5;
if(gi(z)>0)
{
cnt=cnt+gi(z);
}
else
{
return cnt;
break;
}
}
}
Thanks for your wonderfull explanation
#include<bits/stdc++.h>
#define lli long long int
using namespace std;
int main()
{
lli t;
cin>>t;//Testcase
while(t–)
{
lli N;
cin>>N;//N!
lli X = N;
lli NumOfZeroes = 0;
while(X!=0)
{
X = X/5;
NumOfZeroes+=X;}
cout<<NumOfZeroes<<"\n";
}
return 0;
}
#include
using namespace std;
int main()
{
int t;
cin >> t;
for (int k = 0; k < t; k++)
{
int n;
scanf("%d", &n);
int c = 0;
while (n >= 5)
{
n /= 5;
c += n;
}
printf("%d\n", c);
}
return 0;
}
its time complexity is more , than while you do with powers of 5
while (t–)
{
long long n;
cin>>n;
long long power5=5;
long long ans=0;
while (n/power5 >= 1 )
{
ans += n / power5;
power5*=5;
}
cout<<ans<<endl;
}