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

The Archive Base Latest Questions

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

This is a brute force attempt to solve the problem, but it is not

  • 0

This is a brute force attempt to solve the problem, but it is not giving the right answer. The program runs, but its not producing desired output. I believe the logic and program is correct.

This is problem of a famous site (don’t want to a spoiler)

It asks for the number that produces the longest Collatz chain under one million.

class Euler
{

public static void main (String args[])
{
    long len,longLength=0;
    for(long i =3;i<=1000000;i++)
    {
        len = Euler14.numFucs(i);
        System.out.println("Ans"+len+"\t"+i);
        if(len>longLength)
            longLength=len;
    }
    System.out.println(longLength);
}


public static long numFucs(long num)
{
    long count=1,$test=0;
    while(num>1)
    {
        if(num%2==0)
        {
            num=num/2;

        }
        else
        {
            num=3*num+1;

        }
        count++;


    }
    //System.out.println("\tEnd");
    return count;
    }
}
  • 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-23T13:27:25+00:00Added an answer on May 23, 2026 at 1:27 pm

    Well, I feel like it’d be cheating to give you the code for the right answer, as a fellow Project Euler fan. You’re outputting the length of the longest chain, not the number that obtains it. If you really want, I can show you the one line that needs to change, but, honestly, this is a simple fix, and I challenge you to do it yourself.

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

Sidebar

Related Questions

Feeling pretty brain-dead right now. I can, of course, brute-force this, but I feel
I'm trying to solve problem 14 on project euler, and my initial brute force
This evening I noticed a brute force attack attempt from the same IP address
I'm doing some kind of brute force attack to solve a problem. Theoratically it
This is a brute force attempt at the chromatic number of a matrix. It
Is there a less brute-force way to do this? #!/bin/ksh THIS_SCRIPT=$(/usr/bin/readlink -f $(echo $0
I have this grand idea to basically employ some brute force attack to test/verify
I am having some trouble understanding this brute force approach. I am using Perl
Is there a simpler and better way to solve this problem because I used
I'm well aware this brute force method is bad and that I should be

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.