+ 3
Python Semi primes
Can someone please help me understand the following question? A semiprime number is an integer which can be expressed as a product of two distinct primes. For example 15 = 3*5 is a semiprime number but 9 = 3*3 is not . Given an integer number N, find whether it can be expressed as a sum of two semi-primes or not (not necessarily distinct). Input Format: The first line contains an integer N. Output Format: Print 'Yes' if it is possible to represent N as a sum of two semiprimes 'No' otherwise. Example: Input: 30 Output: Yes Explanation: N = 30 can be expressed as 15+15 where 15 is a semi-prime number (5*3 = 15) NOTE: N is less than equal to 200
7 ответов
+ 3
EDIT: Nilutpol Kashyap What part don't you understand?
+ 2
Diego ~ Print 'Yes' if it is possible to represent N as a sum of two semiprimes 'No' otherwise 🤓
+ 2
Your function checkSemiprime(num) doesn't seem to look for semiprimes, but for primes?
+ 2
Nilutpol Kashyap You need a function that checks if a number is prime, another function that checks if a number is semiprime (product of two primes) and a third function that checks if the given number can be expressed as a sum of two semiprimes.
If I were you, I'd calculate the prime numbers up to n, then the semiprimes up to n and store them in a list. Then I'd iterate over the list and check if n is the sum of two items in the list. There might be more efficient methods though
+ 2
Jay Matthews thanks a lot
0
@diego I have written a code. can you please check.
https://code.sololearn.com/cTrqj4BQOskZ/?ref=app
- 1
Anna can you please guide?