Python Semi primes | Sololearn: Learn to code for FREE!
+ 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

5th Mar 2019, 9:29 AM
Nilutpol Kashyap
Nilutpol Kashyap - avatar
7 ответов
+ 3
EDIT: Nilutpol Kashyap What part don't you understand?
5th Mar 2019, 12:25 PM
Diego
Diego - avatar
+ 2
Diego ~ Print 'Yes' if it is possible to represent N as a sum of two semiprimes 'No' otherwise 🤓
5th Mar 2019, 12:43 PM
Anna
Anna - avatar
+ 2
Your function checkSemiprime(num) doesn't seem to look for semiprimes, but for primes?
7th Mar 2019, 6:50 AM
Anna
Anna - avatar
+ 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
7th Mar 2019, 7:00 AM
Anna
Anna - avatar
+ 2
Jay Matthews thanks a lot
7th Mar 2019, 10:24 AM
Nilutpol Kashyap
Nilutpol Kashyap - avatar
0
@diego I have written a code. can you please check. https://code.sololearn.com/cTrqj4BQOskZ/?ref=app
7th Mar 2019, 6:41 AM
Nilutpol Kashyap
Nilutpol Kashyap - avatar
- 1
Anna can you please guide?
7th Mar 2019, 6:54 AM
Nilutpol Kashyap
Nilutpol Kashyap - avatar