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

  • Home
  • SEARCH
  • 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 6150877
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T19:41:07+00:00 2026-05-23T19:41:07+00:00

unsigned long long terms; unsigned long long test; unsigned long long digit = 1;

  • 0
unsigned long long terms;
unsigned long long test;
unsigned long long digit = 1;
unsigned long long max = 0;

//cout<<sizeof(long)<<" "<<sizeof(int)<<endl;
//cout<<digit<<endl;
for(;digit<1000000;++digit)
{
    terms = 1;
    test = digit;
    while(test>1)
    {
        if(0==(test%2))
        {
            test /=2;
        }else{
            test = test *3 +1;
        }
        terms ++;
    }   
    if(terms>max)
        max = terms;
}
//terms = get_chain_length();

/*if(terms>max)
        max = terms;*/
//cout<<sizeof(long long)<<endl;
cout<<max<<endl;

It is out of INT_MAX, how can I correct it? I try to use Hash_map in a recursive way, but stack over.

  • 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-23T19:41:08+00:00Added an answer on May 23, 2026 at 7:41 pm

    This is the Collatz Conjecture. Consider using memoization to solve the problem by storing the lengths of the chains you’ve seen for (e.g. if 6 gives a chain length of 7 and you encounter 6 when processing change N, then you can just add 7 to the chain length so far and immediately return).

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

Sidebar

Related Questions

struct test{ unsigned long int asd[][3][6]; }; sizeof(struct test) returns 0. So, if that
I managed to get a unsigned long int octets-representation (BE) by reading IPv4 methods,
Why is this code throwing up a SIGSEGV : int main() { unsigned long
Given an integer typedef: typedef unsigned int TYPE; or typedef unsigned long TYPE; I
#include <stdio.h> int main() { unsigned long long int num = 285212672; //FYI: fits
#include <iostream> #include <fstream> #include <cstring> using namespace std; typedef unsigned long int WORD;
Can unsigned long int hold a ten digits number (1,000,000,000 - 9,999,999,999) on a
struct DummyStruct{ unsigned long long std; int type; }; DummyStruct d; d.std = 100;
Can anyone tell me how to convert unsigned long long int into vector and
I am using unsigned long to collect performance data while profiling an application as

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.