C language: Determine whether a number is a prime number

Simple c
determines whether a number is prime. Insert picture description hereInsert picture description here
The more troublesome way of writing here is also simpler: Insert picture description here
there are two situations for jumping out of the for loop, the first is when i>=a, and the second is when a can divide i; Therefore, after jumping out of the for loop, judging the comparison of the size of i and a, we can get whether it is a prime number.
However, there is a simpler method: Insert picture description here
According to the mathematical formula, you can know that if you want to find a prime number, you only need to divide 2~ the radical sign itself; but here you must know that i<=sqrt(a), Because when the number you count can be rounded out, it is not a prime number.

Guess you like

Origin blog.csdn.net/m0_52405419/article/details/115356808