How to gracefully judge whether a number is a prime in python?

how do the great gods check whether they are prime numbers? Is there a ready-made module to call?

May.25,2022

look at the answer "

is a similar problem before


elegance is no way to be elegant, only to improve performance as much as possible

import math

def is_prime(number):
    if number > 1:
        if number == 2:
            return True
        if number % 2 == 0:
            return False
        for i in range(3, int(math.sqrt(number) + 1), 2):
            if number % i == 0:
                return False
        return True
    return False

https://www.zhihu.com/questio...
depends on your actual needs. How much prime number do you want to check?
if any large number is judged to be a prime number, the first edition of engineering practice uses a fast check (it is not guaranteed to be a prime number, but the speed is very fast, and the probability that it is not a prime number is very small. This kind of judging prime number can be used in some practice, but can not be regarded as prime number directly in mathematics)
some specific large numbers have specific methods to judge whether they are prime numbers, but this method can only be aimed at specific numbers, not universal
if the numbers are not enough to be hard calculated, the speed will be relatively slow but 100% accurate

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b376a7-2b8e4.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b376a7-2b8e4.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?