IrreducibleNumber
SRM 323 · 2006-10-19 · by Pawa
SRM 323 · 2006-10-19 · by Pawa · Simple Search, Iteration
Problem Statement
Problem Statement
You are given a int[] A. An integer K is irreducible with respect to A if K cannot be represented as a sum of one or more elements from A, where each element of A may be used at most once. Return the smallest positive integer that is irreducible with respect to A.
Constraints
- A will contain between 1 and 3 elements, inclusive.
- Each element of A will be between 1 and 100, inclusive.
Examples
0)
{1,1}
Returns: 3
1 can be expressed as 1, and 2 can be expressed as 1+1.
1)
{1,2}
Returns: 4
2)
{1,3}
Returns: 2
3)
{1,2,4}
Returns: 8
4)
{4, 1, 3}
Returns: 2
Submissions are judged against all 35 archived test cases, of which 5 are shown here. Case numbers match the judge’s.
Coding Area
Language: C++17 · define a public class IrreducibleNumber with a public method int getIrreducible(vector<int> A) · 35 test cases · 2 s / 256 MB per case