Eulerproblem-12 for python

Source: Internet
Author: User

Def ext12 ():
"""
The number sequence of triangles is constructed by concatenation of natural numbers. Therefore, the seventh triangle number is 1 + 2 + 3 + 4 + 5 + 6 + 7 = 28. In this case
The top 10 are:
1, 3, 6, 10, 15, 21, 28, 36, 45, 55...
Below is the approximate number of the first seven triangles we listed:
1: 1
3: 1, 3
6: 1, 2, 3
10: 1, 2, 5, 10
15: 1, 3, 5, 10
21: 1, 3, 7, 21
28: 1, 2, 4, 7, 14, 28
Observe the divisor of the numbers 10, 15, and 28. We can find that the divisor of the last half is equal to the number of the triangle divided by the first half, therefore, we only need to try int (sqrt (n ))
You can. Note that if the number of triangles is exactly the same as the total number of delimiters, only one divisor can be calculated.


"""
Count = 0
N = 1
While count <= 500:
Count = 1
N + = 1
For I in range (1, int (tri (n) x * 0.5) + 1 ):
If not tri (n) % I:
Count + = 2
If int (tri (n) ** 0.5) = tri (n) ** 0.5:
Count-= 1


Print n, tri (n)




Def ext13 ():
From math import sqrt


N = 0
Counter = 0
While counter< = 500:
Counter = 1
N + = 1
For I in range (1, int (sqrt (tri (n) + 1): # Try from 1 to int (sqrt (tri (n )))
If not tri (n) % I:
Counter + = 2


If int (sqrt (tri (n) = sqrt (tri (n )):
Counter-= 1
# Print counter
Print n, tri (n)

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.