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 7005217
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T21:19:24+00:00 2026-05-27T21:19:24+00:00

We have started learning Java in school, and we have been given a few

  • 0

We have started learning Java in school, and we have been given a few homeworks to do. I’ve managed to do 4 out of 5, but this last one is a real pain.

Basicly: Write a program that finds (in a 1000 places long number) the largest product of five
consecutive digits.

Here’s the number http://pastebin.com/PFgL6jcM

Do you have any ideas how to solve this ?

If this are unclear instruction, notify me and will try to explain to you again.

  • 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-27T21:19:25+00:00Added an answer on May 27, 2026 at 9:19 pm

    I’d say an optimized algorithm would look like this:

    1) grab first five numbers

    2) if current set contains a 0, grab the first five numbers after the 0. Do this until you reach a set that doesn’t contain a 0. (if all sets contain a 0 – unlikely – return 0).

    3) compute the product of the 5 numbers ( x1, x2, x3, x4, x5 ) like so:

    p1 = x5 * x4
    p2 = x3 * p1
    p3 = x2 * p2
    p  = x1 * p3
    

    4) if p is greater than the previous p, store it.

    5) discard the first number and add the next one (x6).

    p = x6 * p3
    

    6) if the new p is greater than the old one, go to step 3)

    You’re reducing the number of multiplications by a factor of 5, since you won’t keep multiplying 5 numbers, but 2.

    Remember to discard sequences that contain a 0 and try to optimize the algorithm along these lines.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have just started learning NHibernate. Over the past few months I have been
I have been learning ASP.NET MVC in the last few months and I think
I am just starting out learning Java, GAE etc. I have started a project
I have just started learning about Java server faces and successfully tested out my
All, I started learning Java threads in the past few days and have only
I have just started learning Erlang and am trying out some Project Euler problems
I have recently started learning F#, and this is the first time I've ever
I have recently started learning Perl and one of my latest assignments involves searching
I've been a web developer for some time now, and have recently started learning
I've downloaded the JAVA Eclipse IDE and started learning Java. I have a good

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.