 
  Data Structure Data Structure
 Networking Networking
 RDBMS RDBMS
 Operating System Operating System
 Java Java
 MS Excel MS Excel
 iOS iOS
 HTML HTML
 CSS CSS
 Android Android
 Python Python
 C Programming C Programming
 C++ C++
 C# C#
 MongoDB MongoDB
 MySQL MySQL
 Javascript Javascript
 PHP PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Checking semiprime numbers - JavaScript
We are required to write a JavaScript function that takes in a number and the function establishes if the provided number is a semiprime or not.
Semiprime
A semiprime number is that number which is a special type of composite number that is a product of two prime numbers. For example: 6, 15, 10, 77 are all semiprime. The square of a prime number is also semiprime, like 4, 9, 25 etc.
Example
Following is the code to check semi-prime numbers −
const num = 141; const checkSemiprime = num => {    let cnt = 0;    for (let i = 2; cnt < 2 && i * i <= num; ++i){       while (num % i == 0){          num /= i, ++cnt;       }    }    if (num > 1){       ++cnt;    }    // Return '1' if count is equal to '2' else    // return '0'    return cnt === 2; } console.log(checkSemiprime(num)); Output
Following is the output in the console −
true
Advertisements
 