TopcoderARCHIVE
Archive/Problems/EllysPalMulDiv2
SRM · Problem 16136

EllysPalMulDiv2

Problem statement, definition, constraints, and public examples.

Problem Statement

We call a number a palindrome if it reads the same from left to right as it does from right to left. For example, some palindromic numbers are 6, 11, 121, 666, 100001, and 123454321. Note that the number 47740 is not a palindrome (as you are not allowed to have unnecessary leading zeros).

Elly has the integer X. Now she wants to find the lowest integer 1 ≤ Y ≤ 1,000, such that the product X * Y is a palindrome (if there is such a number).

Let's look at several examples:
  • If X = 42, then Y is 6 (42 * 6 = 252).
  • If X = 121, then Y = 1 (121 * 1 = 121).
  • If X = 1337, then Y = 143 (1337 * 143 = 191191).
  • If X = 13, then Y = 38 (13 * 38 = 494).
  • If X = 100, then no Y can make it a palindrome.
  • If X = 39325, then Y = 1337 would make it a palindrome (39325 * 1337 = 52577525), but this Y isn't in the bounds [1, 1000].
Given the int X, return the lowest integer Y in the interval [1, 1000] that makes the product X * Y a palindrome, or -1 if there is no such Y.

Definition

Class:
EllysPalMulDiv2
Method:
getMin
Parameters:
int
Returns:
int
Method signature:
int getMin(int X)
(be sure your method is public)

Constraints

  • X will be between 1 and 100,000, inclusive.

Examples

  1. 42
    Returns: 6
  2. 121
    Returns: 1
  3. 1337
    Returns: 143
  4. 13
    Returns: 38
  5. 100
    Returns: -1
  6. 39325
    Returns: -1
← All problems