The method of realizing GCD and judging prime number in Python

Source: Internet
Author: User
Tags gcd in python

In this paper, we illustrate how Python realizes gcd and judging primes. Share to everyone for your reference. The implementation methods are as follows:

?

1 2 3 4 5 6 7 8 9 10 11-12 #!/usr/bin/env python def showmaxfactor (num): Count = Num/2 while count > 1:if num% count = 0:print ' largest fact Or of%d '%d ' (num, count) break #break跳出时会跳出下面的else语句 count = 1 else:print num, "is prime" for Eachnum in range (10, ): Showmaxfactor (Eachnum)

The results of the operation are as follows:

?

1 2 3 4 5 6 7 8 9 10 11 Largest factor the 5 is prime largest factor of ' 6 ' is prime largest factor ' is 7 largest factor of 15 is 5 largest factor the 8 is prime largest factor an IS 9 are prime largest factor of is 10

I hope this article will help you with your Python programming.

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.