forked from Twiggecode/Integer-Sequences
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSemiPrime.cpp
43 lines (37 loc) · 876 Bytes
/
SemiPrime.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#include <bits/stdc++.h>
using namespace std;
// Utility function to check whether
// number is semiprime or not
int checkSemiprime(int num)
{
int cnt = 0;
for (int i = 2; cnt < 2 && i * i <= num; ++i)
while (num % i == 0)
num /= i, ++cnt; // Increment count
// of prime numbers
// If number is greater than 1, add it to
// the count variable as it indicates the
// number remain is prime number
if (num > 1)
++cnt;
// Return '1' if count is equal to '2' else
// return '0'
return cnt == 2;
}
// Function to print 'True' or 'False'
// according to condition of semiprime
void semiprime(int n)
{
if (checkSemiprime(n))
cout << "True\n";
else
cout << "False\n";
}
// Driver code
int main()
{
int n;
cin>>n;
semiprime(n);
return 0;
}