Use Python to find the 1000th prime number value

Source: Internet
Author: User

Today in the group has the Netizen question:

Ask for a 1000th prime number starting with Python 0?

In fact, the algorithm itself is not difficult to find the prime number from the definition of prime numbers.

Prime: A number that can only be divisible by 0 and itself. Well, let's start writing a program (a small algorithm).

#coding =utf-8
    
#定义求质数的函数
def getprim (n):
#我们从3开始, improve efficiency, oh, very little
p=3
x=0 while
(x<n):
result=true for
i in range (2,p-1):
if (p%i==0):
result=false
if result==true:
x=x+1
rst=p
#注意: This adds 2 to improve efficiency, since being an extra number is definitely not prime.
p=+2
Print (RST)
    
#调用函数
Getprim (1000)

The result: 7927

The results of the operation are shown below:

By the way: In fact all languages are figured out, important is the algorithm, so master the basis of the classical algorithm is still very necessary drop ~ ~

More Wonderful content: http://www.bianceng.cnhttp://www.bianceng.cn/Programming/extra/

Related Article

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.