K. Owl Geeks

Codeforces
IDCF10135K
Time1000ms
Memory256MB
Difficulty
English · Original
Formal · Original
The owls have the following equation: Y = a × x2 + b × x With a, b, and N given, they decide to put into a set the integer values of Y that are less than or equal to N and that are outputted from the equation from any positive integer x. With that set of numbers, they come up with the problem of finding the winning digit among them. The winning digit is a digit from 0 to 9 that will get the maximum number of points. How are points for a digit calculated you may ask? Well, be a bit more patient, I’m going to tell you now. For each number in the set, if the digit was the most repeated digit or tied with other digits as the most repeated digit in the ith number of set S, then it would get one point from that ith number. Can you tell the owls what the winning digit is? The first line of input is T – the number of test cases. The first line of each test case is a, b, and N (1 ≤ a, b, N ≤ 105). For each test case, print on a line the winning digit with the maximum number of points. If there is a tie, print the minimum digit among them. If the set is empty, print  - 1. ## Input The first line of input is T – the number of test cases.The first line of each test case is a, b, and N (1 ≤ a, b, N ≤ 105). ## Output For each test case, print on a line the winning digit with the maximum number of points. If there is a tie, print the minimum digit among them. If the set is empty, print  - 1. [samples]
**Definitions** Let $ T \in \mathbb{Z} $ be the number of test cases. For each test case, let $ a, b, N \in \mathbb{Z} $ with $ 1 \leq a, b, N \leq 10^5 $. Define the quadratic function $ Y(x) = a \cdot x^2 + b \cdot x $ for $ x \in \mathbb{Z}^+ $. Let $ S = \{ Y(x) \mid x \in \mathbb{Z}^+, Y(x) \leq N \} $ be the set of valid outputs. **Constraints** 1. $ 1 \leq T \leq 10^5 $ 2. $ 1 \leq a, b, N \leq 10^5 $ 3. $ S $ may be empty. **Objective** For each $ y \in S $, let $ d(y) $ be the multiset of decimal digits of $ y $. For each digit $ d \in \{0, 1, \dots, 9\} $, define its score $ s(d) $ as the number of $ y \in S $ in which $ d $ is among the most frequently occurring digits (i.e., tied for maximum frequency in $ d(y) $). Find $ \min \{ d \in \{0, \dots, 9\} \mid s(d) = \max_{d' \in \{0,\dots,9\}} s(d') \} $. If $ S = \emptyset $, output $ -1 $.
API Response (JSON)
{
  "problem": {
    "name": "K. Owl Geeks",
    "description": {
      "content": "The owls have the following equation: Y = a × x2 + b × x With a, b, and N given, they decide to put into a set the integer values of Y that are less than or equal to N and that are outputted from th",
      "description_type": "Markdown"
    },
    "platform": "Codeforces",
    "limit": {
      "time_limit": 1000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "CF10135K"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "The owls have the following equation:\n\nY = a × x2 + b × x\n\nWith a, b, and N given, they decide to put into a set the integer values of Y that are less than or equal to N and that are outputted from th...",
      "is_translate": false,
      "language": "English"
    },
    {
      "statement_type": "Markdown",
      "content": "**Definitions**  \nLet $ T \\in \\mathbb{Z} $ be the number of test cases.  \nFor each test case, let $ a, b, N \\in \\mathbb{Z} $ with $ 1 \\leq a, b, N \\leq 10^5 $.  \nDefine the quadratic function $ Y(x) =...",
      "is_translate": false,
      "language": "Formal"
    }
  ]
}
Full JSON Raw Segments