Project Euler Question 14 (Collatz Problem)

后端 未结 8 1904
清酒与你
清酒与你 2020-11-27 07:58

The following iterative sequence is defined for the set of positive integers:

n ->n/2 (n is even) n ->3n + 1 (n is odd)

Using the rule above and starting wit

8条回答
  •  旧巷少年郎
    2020-11-27 08:07

    Having just tested it in C#, it appears that 113383 is the first value where the 32-bit int type becomes too small to store every step in the chain.

    Try using an unsigned long when handling those big numbers ;)

提交回复
热议问题