Repdigit Number

AtCoder
IDarc149_a
Time2000ms
Memory256MB
Difficulty
You are given positive integers $N$ and $M$. Find the maximum positive integer $X$ that satisfies all of the following conditions. * $X$ is a positive integer less than $10^N$, and all digits in the decimal representation of $X$ are the same. * $X$ is a multiple of $M$. If no positive integer $X$ satisfies the conditions, print `-1`. ## Constraints * $1\leq N\leq 10^5$ * $1\leq M\leq 10^9$ ## Input The input is given from Standard Input in the following format: $N$ $M$ [samples]
Samples
Input #1
7 12
Output #1
888888

Four positive integers $X$ satisfy the conditions: $444, 888, 444444, 888888$. The answer is the maximum of them, which is $888888$.
Input #2
9 12
Output #2
888888888

Six positive integers $X$ satisfy the conditions: $444, 888, 444444, 888888, 444444444, 888888888$.
Input #3
1 3
Output #3
9

Three positive integers $X$ satisfy the conditions: $3, 6, 9$.
Input #4
1000 25
Output #4
\-1

No positive integers $X$ satisfy the conditions.
Input #5
30 1
Output #5
999999999999999999999999999999
API Response (JSON)
{
  "problem": {
    "name": "Repdigit Number",
    "description": {
      "content": "You are given positive integers $N$ and $M$. Find the maximum positive integer $X$ that satisfies all of the following conditions. *   $X$ is a positive integer less than $10^N$, and all digits in th",
      "description_type": "Markdown"
    },
    "platform": "AtCoder",
    "limit": {
      "time_limit": 2000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "arc149_a"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "You are given positive integers $N$ and $M$. Find the maximum positive integer $X$ that satisfies all of the following conditions.\n\n*   $X$ is a positive integer less than $10^N$, and all digits in th...",
      "is_translate": false,
      "language": "English"
    }
  ]
}
Full JSON Raw Segments