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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T02:41:41+00:00 2026-05-25T02:41:41+00:00

I have recently started reading Programming Challenges book by S. Skiena and believe or

  • 0

I have recently started reading “Programming Challenges” book by S. Skiena and believe or not I am kind of stuck in the very first problem.

Here’s a link to the problem: 3n+1 problem

Here’s my code:

 #include <stdio.h>

long get_cycle(long input){
    if (input == 1){
        return 1;
    }
    else{
        if (input & 1){
            return 2 + get_cycle((3*input+1)>>1);
        }
        else{
            return 1 + get_cycle(input >> 1);
        }
    }
}

long get_range_cycle(int k, int j){
    int i;
    int max = 0;
    int current_cycle;
    int to = k > j ? k : j;
    int from = k < j ? k : j;
    for (i=from; i<=to; ++i){
        current_cycle = get_cycle(i);
        if (current_cycle > max){
            max = current_cycle;
        }
    }
    return max;
}

int main(){
    long p, q;
    long re[100][3];
    int i = 0;
    while (scanf("%ld %ld",&p,&q) == 2){
        re[i][0] = p;
        re[i][1] = q;
        re[i][2] = get_range_cycle(p,q);
        ++i;
    }
    int j;
    for (j=0; j<i; ++j){
        printf("%ld %ld %ld\n",re[j][0],re[j][1],re[j][2]);
    }
}

what is wrong with my code? the input and out is exactly the same with sample.But the submission result is always run time error!

  • 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-25T02:41:42+00:00Added an answer on May 25, 2026 at 2:41 am

    You’re code seems to assume maximum 100 lines in the input file – the sample data they are testing on might be bigger? They make no explicit claim wrt the maximum set size of the input data.

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

Sidebar

Related Questions

I have recently started learning Ruby, as my first programming language. I feel comfortable
I have recently started working on a very large C++ project that, after completing
I have recently started learning F#, and this is the first time I've ever
I have only recently started programming significantly, and being completely self-taught, I unfortunately don't
I have recently started reading up on Grails and would like to use SQL
I have recently started learning java as my first ever step into object oriented
I recently started reading Evans' Domain-Driven design book and started a small sample project
I have recently started reading about Java EE6 and in the examples I follow
I have recently started programming in Perl (I'll skip the long story) but I've
I have recently started having problems with TortoiseCVS, or more specifically with plink, the

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.