TopCoder problem "MixedUpPrimes" used in TCCC06 Qual 3 (Division I Level Three)



Problem Statement

    Using the operators '+', '-', '/', '*', and parentheses as many times as you wish, find expressions for the smallest and largest primes that use each element of values exactly once. A prime is an integer greater than 1 with no divisors except 1 and itself. Return a int[] with exactly two elements, where the first element is the smallest prime you can make, and the second is the largest. If no primes can be constructed, return an empty int[].
 

Definition

    
Class:MixedUpPrimes
Method:findPrimes
Parameters:int[]
Returns:int[]
Method signature:int[] findPrimes(int[] values)
(be sure your method is public)
    
 

Notes

-The division operator truncates its results. For example, 8/5 = 1.
-The given numbers cannot be concatenated. For example, 8 and 5 cannot be combined to form 85.
 

Constraints

-values will contain between 1 and 6 elements, inclusive.
-Each element of values will be between 1 and 30, inclusive.
 

Examples

0)
    
{1,2}
Returns: {2, 3 }
We get 2 using 2*1. We get 3 using 2+1.
1)
    
{1,2,3}
Returns: {2, 7 }
Here we use 3-2+1=2 and 3*2+1 = 7.
2)
    
{1,2,3,4,5,6}
Returns: {2, 719 }
3)
    
{2,3,5,7,11,13}
Returns: {2, 15017 }
4)
    
{2,2,2,2,2,2}
Returns: {2, 17 }
5)
    
{8}
Returns: { }

Problem url:

http://www.topcoder.com/stat?c=problem_statement&pm=6163

Problem stats url:

http://www.topcoder.com/tc?module=ProblemDetail&rd=10095&pm=6163

Writer:

AdminBrett

Testers:

PabloGilberto , vorthys , Olexiy

Problem categories:

Dynamic Programming, Math, Recursion, String Parsing