Untitled

mail@pastecode.io avatar
unknown
python
a year ago
968 B
3
Indexable
Never
from math import * 


# check if a number is prime 
def is_prime(n):
    # 0 and 1 are not prime numbers 
    # we return false directly 
    if n<=1:
        return False
    # we start from 2 because 1 always devide any number 
    # +1  because we need to reach sqrt(n) and range exclude last element
    for i in range(2, int(sqrt(n))+1):
        # we found a divider that is diffrenet from 1 and n
        if n%i == 0 :  
            return False
    # after we finish the loop ,  that mean there is no diveder for n !=1 and !=n
    return True 
    
def is_prime(n):
    if n<=1:
        return False
    for i in range(2, int(sqrt(n))+1):
        if n%i == 0 :  
            return False
    return True 
    
# n=p*k    
def semi_prime(n):
    for i in range ( 2, int(n/2) + 1):
        if n%i ==0 : 
            p=i
            k=n/i
            if is_prime(p) and is_prime(k):
                return True 
    return False 
            
print(semi_prime(24))