3n+1 Run TIme Error

Write here if you have problems with your C++ source code

Moderator: Board moderators

3n+1 Run TIme Error

Postby anjaneyanjan7 » Tue Nov 02, 2010 8:37 pm

Code: Select all
#include <iostream>


using namespace std;

int main()
{
   long long a,c,b,*arr,i,max=0,n,num;
   
   while(cin >> a >> b){
      arr = new long long[b-a];
      
   
      if(a>b){
        c = a;
        a = b;
        b = c;
      }
      
      max = 0;
      for(i=0;i<b-a+1;i++){
         arr[i] = a+i;
      }

      for(i=0;i<b-a+1;i++){
         n = arr[i];
         num=1;
      
         while(n!=1){
            num++;
            if(n<=b && n>=a)
                   arr[n-a] = 1;   
            if(n%2 == 0){
               n = n/2;
            }
               
            else
               n = 3*n + 1;
         }
         if(max < num)
            max=num;
      }
      
      cout << a << " " << b << " " << max<<endl;      

   }
      return 0;
}


kindly let me knw why I am getting runtime error message


Hi,

This is an automated response from UVa Online Judge.

Your submission with number 8368446 for the problem 100 - The 3n + 1 problem has failed with verdict Runtime error.

This means that the execution of your program didn't finish properly. Remember to always terminate your code with the exit code 0.

Best regards,

The UVa Online Judge team
anjaneyanjan7
New poster
 
Posts: 2
Joined: Tue Nov 02, 2010 8:33 pm

Re: 3n+1 Run TIme Error

Postby niemic » Wed Jan 12, 2011 11:24 pm

The max number of elements is greater than your array.

Example:

input value of 3 -> 3 10 5 16 8 4 2 1 , so there will be 8 elements
niemic
New poster
 
Posts: 1
Joined: Wed Jan 12, 2011 11:04 pm


Return to C++

Who is online

Users browsing this forum: Google [Bot] and 1 guest