In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces js how to verify whether a number is a prime number, the article is very detailed, has a certain reference value, interested friends must read it!
Verify whether a number is a prime
1. If the number is 2 or 3, it must be prime
2. If it is an even number, it must not be a prime
3. If this number is not divisible by 3mure-any of its square roots, m must be a prime. And the divisor can be incremented each time (excluding even numbers)
Function isPrime (num) {
If (num = 2 | | num = 3) {
Return true
}
If (num% 2 = = 0) {
Return false
}
Let divisor = 3 limit = Math.sqrt (num)
While (limit > = divisor) {
If (num% divisor = = 0) {
Return false
}
Else {
Divisor + = 2
}
}
Return true
}
Console.log (isPrime (30)); / / false
The above is all the content of the article "how to verify whether a number is a prime by js". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.