Leaderboard
Showing:
Handle Score
@Ibrahim Nash 6420
@blackshadows 6380
@mb1973 5642
@Quandray 5233
@akhayrutdinov 5111
@saiujwal13083 4610
@sanjay05 3762
@kirtidee18 3673
@marius_valentin_dragoi 3522
@sushant_a 3459
@verma_ji 3413
Complete Leaderboard
Express N as sum of 4 prime numbers
Easy Accuracy: 43.14% Submissions: 26 Points: 2

Given a number N, the task is to express N as a summation of 4 positive primes.
 

Example 1:

Input: N = 8
Output: 2 2 2 2
Explanation: 2 is prime and 2 + 2 + 2 + 2 = 8

Example 2:

Input: N = 15
Output: 2 3 3 7
Explanation: 2, 3 and 7 are prime and 2 + 3 + 
+ 3 + 7 = 15.

 

Your Task:
You don't need to read or print anything. Your task is to complete the function Express() which takes N as input parameter and returns a list of four number if N can be expressed as a summation of four numbers otherwise returns a list containing -1. The returned list should be in increasing order. If there are more than one list possible then returns the lexicograhically smallest one.

 

Expected Time Complexity: O(N*log(N))
Expected Space Complexity: O(N)

Constraints:
1 <= N <= 105

to report an issue on this page.

Editorial

We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?

Yes

All Submissions

My Submissions:

Login to access your submissions.

Express N as sum of 4 prime numbers

Output Window