On WWDC 2014, no mention of iOS 88 daxin features

Source: Internet
Author: User

Title

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

nn/2 (is n even)
n3 n + 1 (is n odd)

Using the rule above and starting with, we generate the following sequence:

13 40 20 10 5 16 8 4 2 1

It can be seen the sequence (starting at and finishing at 1) contains terms. Although it had not been proved yet (Collatz problem), it was thought that all starting numbers finish at 1.

Which starting number, under one million, produces the longest chain?

Note: Once The chain starts the terms is allowed to go above one million.

Translation:

The following sequence of loops is composed of positive integers according to the following rules:

n→ n /2 (if n an even number)

n→3 n + 1 (if n an odd number)

If the sequence starts at 13, the following sequence is generated:

13→40→20→10→5→16→8→4→2→1

Obviously the above series have 10 numbers, although not proven (famous Collatz conjecture), but we think that no matter what the number starts, the series will end at 1. Therefore, once the sequence has produced 1, it is considered to be the end of the series.

The question this time is: according to the above rule, which number under 1 million can produce the longest series?

Please note: The resulting sequence may contain items that are more than 1 million in number.

Import Timedef f (n):    if N%2==1 and n>1:       return F (3*n+1) +1    elif n%2==0:       return F (N/2) +1    return 1m , Value=0,0begin=time.time () for I in Range (1,1000000):    tmp=f (i)    if tmp>m:        value=i        M=tmpprint Time.time ()-beginprint M,value



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.