You are not logged in. Please login at www.codechef.com to post your questions!

×

FCTRL Error

Here is my code for the problem where we need to find the number of trailing zeros in the factorial of a given number. Link here

#include<bits/stdc++.h>
using namespace std;
long long z(long long a)
{//number of trailing zeroes in a!
    int sum=0,t,b=1;
    while(t!=0)
    {
        t=a/pow(5,b);
        b++;
        sum=sum+t;

    }
    return sum;
}
int main() {
    long long t,a;

    cin>>t;

    while(t--)
    {
        cin>>a;
        cout<<z(a)<<endl;
    }
    return 0;
}

I am not getting a correct answer. Is there something wrong in the logic or am I missing something minute?

asked 24 May '14, 13:36

gursheel07's gravatar image

2★gursheel07
12
accept rate: 0%


You are not initializing t . t can be 0 initially and so it will not go in the loop . Here is your corrected code .

#include<bits/stdc++.h>
using namespace std;
long long z(long long a)
{//number of trailing zeroes in a!
    int sum=0,t=1,b=1;
    while(t!=0)
    {
        t=a/pow(5,b);
        b++;
        sum=sum+t;

    }
    return sum;
}
int main() {
    long long t,a;

    cin>>t;

    while(t--)
    {
        cin>>a;
        cout<<z(a)<<endl;
    }
    return 0;
}
link

answered 24 May '14, 14:28

the65bit's gravatar image

4★the65bit
1.1k101328
accept rate: 13%

toggle preview
Preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported
  • mathemetical formulas in Latex between $ symbol

Question tags:

×1,901
×45

question asked: 24 May '14, 13:36

question was seen: 735 times

last updated: 24 May '14, 14:28