I solved the 3n+1 problem with two methods. One is Brute-Force, Time limit exceeded .
The other is set a cache[] array to save the previous computed cycle-length.
A solution in Java (I found it through google), and I rewrite it in C, but the Java solution AC , while reimplemented C solution Time ...
Search found 2 matches
- Thu Jul 03, 2014 3:50 pm
- Forum: Volume 1 (100-199)
- Topic: 100 - The 3n + 1 problem
- Replies: 1394
- Views: 320786
- Thu Jul 03, 2014 3:37 pm
- Forum: Volume 1 (100-199)
- Topic: 100 - The 3n + 1 problem
- Replies: 1394
- Views: 320786
Re: 3n+ 1 : y u always go WA/RUNTIME!?
int oddEven(int x);
If x is 113383, oddEven() has a dead loop, 3*x+1 and x/2 will lead to a number out of range of int (2^31)
int oddEven(long long x) will be ok.
113383 is just one of the numbers that will be out of 2^31
If x is 113383, oddEven() has a dead loop, 3*x+1 and x/2 will lead to a number out of range of int (2^31)
int oddEven(long long x) will be ok.
113383 is just one of the numbers that will be out of 2^31