TopcoderArchiveVisit Topcoder
Archive
Algorithm problem

BetaHard

Problem statement, definition, constraints, and public examples.

Problem Statement

Class name: BetaHard
Method name: solve
Parameters: String[]
Returns: int

Implement a class BetaHard, which contains a method solve. solve takes as
parameters a String[] of the form "a,b" and returns the smallest non-negative
integer x such that x%a==b for all elements in the String[].

The String[] will contain elements of the form "int,int", like "19,3", "20,4",
and "5,1".  There is exactly one comma and no space between the integers.  The
first string "19,3" means x satisfies x % 19 == 3, likewise "20,4" means x % 20
== 4. All conditions in the String[] must be met.  Note: Quotes are included
for clarity only and are not included in the String[] elements.

If there is no number which meets the criterion specified, the method returns -1.

The method signature is:
public int solve(String[] al);

The String[] contains between 1 and 5 elements, inclusive.
Each String in the String[] of the correct form: "int,int".
The first number within each String is less than 20 and greater than 0.
The second number within each String is less than 20 and greater than or equal
to 0.

Examples:
-If the String[] is {"2,1","3,1","5,1"}, the method returns 1, since 1 is the
first non-negative integer x such that:
        x % 2 == 1, x % 3 == 1, and x % 5 == 1.

-If the String[] is {"7,2", "9,3"}, the method returns 30, since 30 is the
first non-negative integer x such that:
        x % 7 == 2, and x % 9 == 3.

-If the String[] is {"4,3", "8,4"}, the method returns -1, since there are no
integers x such that:
        x % 4 == 3, and x % 8 == 4.

Definition

Class:
BetaHard
Method:
solve
Parameters:
String[]
Returns:
int
Method signature:
int solve(String[] param0)
(be sure your method is public)

Constraints

    Examples

      No public sample cases were explicitly marked for this problem in the original data.

      Back to all problems