Connection Status:
Competition Arena > EllysPalMulDiv2
SRM 785 · 2020-05-08 · by espr1t · Brute Force
Class Name: EllysPalMulDiv2
Return Type: int
Method Name: getMin
Arg Types: (int)
Problem Statement

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.

Constraints

  • X will be between 1 and 100,000, inclusive.
Examples
0)
42
Returns: 6
1)
121
Returns: 1
2)
1337
Returns: 143
3)
13
Returns: 38
4)
100
Returns: -1

Submissions are judged against all 102 archived test cases, of which 5 are shown here. Case numbers match the judge’s.

Coding Area

Language: C++17 · define a public class EllysPalMulDiv2 with a public method int getMin(int X) · 102 test cases · 2 s / 256 MB per case

Submitting as anonymous