TopcoderArchive
Archive
Algorithm problem

TwistedNumbers

Problem statement, definition, constraints, and public examples.

Problem Statement

Let us call an integer x lucky if ends with 777. For example, numbers 2777, 23777, 777 are lucky, but numbers 317, 21377, 7 are not.

Let us call an integer x twisted if ax + b is lucky for some 1 <= a <= A, 0 <= b <= B.

You are given ints X, A and B. Return "YES" if X is twisted, or "NO" if it is not (all quotes for clarity).

Definition

Class:
TwistedNumbers
Method:
check
Parameters:
int, int, int
Returns:
String
Method signature:
String check(int X, int A, int B)
(be sure your method is public)

Constraints

  • X will be betweeen 1 and 1000, inclusive.
  • A will be between 1 and 10, inclusive.
  • B will be between 0 and 10, inclusive.

Examples

  1. 777
    2
    1
    Returns: "YES"
    777 is lucky by itself, so a = 1, b = 0 are OK.
  2. 776
    1
    1
    Returns: "YES"
    1 * 776 + 1 = 777, so 776 is twisted.
  3. 888
    2
    2
    Returns: "YES"
    2 * 888 + 1 = 1777 is lucky.
  4. 888
    2
    0
    Returns: "NO"
  5. 846
    10
    10
    Returns: "YES"
  6. 846
    10
    8
    Returns: "NO"
  7. 846
    7
    10
    Returns: "NO"
Back to all problems