TopcoderArchiveVisit Topcoder
TCO7 May 2011
TCO11 Qual 3

AllButOneDivisor

Problem statement, definition, constraints, and public examples.

Problem Statement

You are given a int[] divisors containing K elements. Find a positive integer n such that exactly K-1 elements of divisors are exact divisors of n. If there are several such numbers n, return the smallest possible one. If no such number n exists, return -1 instead.

Definition

Class:
AllButOneDivisor
Method:
getMinimum
Parameters:
int[]
Returns:
int
Method signature:
int getMinimum(int[] divisors)
(be sure your method is public)

Notes

  • A number x is an exact divisor of y if y divided by x yields an integer result.
  • If x is an exact divisor of y then we call y a multiple of x.

Constraints

  • divisors will contain between 2 and 6 elements, inclusive.
  • Each element of divisors will be distinct.
  • Each element of divisors will be between 1 and 15, inclusive.

Examples

  1. {2,3,5}
    Returns: 6
    There are many possible values for n in this case. For example: 6, 15, 75 and 12. 6 is the smallest of them.
  2. {2,4,3,9}
    Returns: 12
  3. {3,2,6}
    Returns: -1
    Every multiple of 3 and 2 is also a multiple of 6. Every multiple of 6 is also a multiple of 2 and 3. Therefore, a number that is a multiple of exactly 2 out of the three elements in this array cannot exist.
  4. {6,7,8,9,10}
    Returns: 360
  5. {10,6,15}
    Returns: -1
Back to all problems