Date created: 10/13/12 20:37:13. Last modified: 08/06/16 22:10:53

Problem 14

#include 
#include 

using namespace std;

int main() {

  long long ubound = 1000000, lbound = 500000;
  long long testnumber, highestnumber = 0, lastnumber = 0; 
  int length = 0, longest = 0;

  while (ubound>=lbound) {
    testnumber = ubound;
    length = 1;
    while (testnumber>1) {
      if(testnumber%2==0) {
        testnumber = testnumber/2;
      } else {
        testnumber = (testnumber*3)+1;
      }
      length++;
    }
    if (length>longest) {
      longest = length;
      highestnumber = ubound;
      lastnumber = testnumber;
    }
    ubound--;
  }
  cout << "longest: " <<  longest << " highest: " << highestnumber 
       << " last number: " << lastnumber << endl;
return 0;
}

Previous page: Problem 13
Next page: Problem 16