Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6210033
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T06:05:24+00:00 2026-05-24T06:05:24+00:00

I am trying to develop code for SPOJ factorial problem number 11. The following

  • 0

I am trying to develop code for SPOJ factorial problem number 11. The following is my code

import java.math.*; 
import java.io.*;
public class Problem11 {

/**
 * Count the number of zeroes at the end of 
 * the factorial value of a number.
 */
public static void main(String[] args) throws IOException
{
 BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
 int numOfInputs=0;
 numOfInputs=Integer.parseInt(br.readLine());
 BigInteger nextNum[]=new BigInteger[numOfInputs];
 BigInteger factValue[]=new BigInteger[numOfInputs];

 //Get all the numbers to be computed
 for(int count=0;count<numOfInputs;count++)
 {
    nextNum[count]=new BigInteger(br.readLine());
 }

 //Obtain the factorial value for each number
 for(int count=0;count<numOfInputs;count++)
 {
     factValue[count]=getFact(nextNum[count]);
 }

 //Obtain the number of trailing zeroes
 for(int count=0;count<numOfInputs;count++)
 {
     //System.out.println(factValue[count]);
     System.out.println(getZeroes(factValue[count]));

 }
}


public static String getZeroes(BigInteger num) 
 {
    int numOfZeroes=0;
    while(num.remainder(BigInteger.TEN).equals(BigInteger.ZERO))
    {
        num=num.divide(BigInteger.TEN);
        numOfZeroes++;
    }
    return String.valueOf(numOfZeroes);
 }



public static BigInteger getFact(BigInteger num) 
{
    BigInteger factorial=BigInteger.ONE;    
    if(num.equals(0))
    {
      return (BigInteger.valueOf(1));
    }
    else
    {
        int count=1;
        while((BigInteger.valueOf(count).compareTo(num))<=0)        
        {               
            factorial=factorial.multiply(BigInteger.valueOf(count));
            count++;
        }
    }

    return factorial;

}

}

The code works fine for numbers up to 5 digits with small delay and for the last number
8735373 it is taking too much time, if I submit my solution, the judge shows compilation error.. I am unable to figure out whats the error. Please have a look at my code and help me to trace the problem.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T06:05:25+00:00Added an answer on May 24, 2026 at 6:05 am

    You might look at this method for finding the number of trailing zeros in n!.

    import java.util.*;
    
    public class Main {
    
        public static void main(String[] args) {
            Scanner in = new Scanner(System.in);
            int count = in.nextInt();
            for (int i = 0; i < count; i++) {
                int n = in.nextInt();
                int result = 0;
                for (int d = 5; d <= n; d *= 5) {
                    result += n / d;
                }
                System.out.println(result);
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is the code I'm trying to develop: Public Structure Statistic(Of t) Dim maxStat
I'm trying to develop a simple kernel using TASM, using this code: ; beroset.asm
I'm trying to develop a captcha class for my website everything was doing fine
I am trying to develop a multimedia site and I am leaning heavily toward
I am trying to develop a .NET Web Project using NHibernate and Spring.NET, but
I am trying to develop everything in sharepoint as features so I can easily
I am trying to develop an online translation service (sort of a personal challenge)
I'm trying to develop some SharePoint workflows for the company I work for, and
I'm trying to develop an application that will use getImageData in javascript in Firefox
I'm trying to develop a little C# application (with MS Visual Express and SQL

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.