Euler Project question in Python

Source: Internet
Author: User

# This Python file uses the following encoding:utf-8
# The Fibonacci sequence is defined by the recurrence relation:

# Fn = fn−1 + fn−2, where F1 = 1 and F2 = 1.
# Hence The first terms would be:

# F1 = 1
# F2 = 1
# F3 = 2
# F4 = 3
# F5 = 5
# F6 = 8
# F7 = 13
# F8 = 21
# F9 = 34
# F10 = 55
# F11 = 89
# F12 = 144
# The 12th term, F12, are the first term to contain three digits.

# What's the first term in the Fibonacci sequence to contain? digits?
Import time
Start = Time.time ()
i = 1
j = 1
result = 1
Count = 2
While J:
I, j = j, I + j
Count + = 1
If Len (str (j)) = = 1000:
result = J
Break
print "%sth Fibonacci sequence number contains + digits was found in%s seconds"% (count, Time.time ()-start)

Euler Project question in Python

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.