188. Quaternary Addition

Codeforces
IDCF10269188
Time1000ms
Memory256MB
Difficulty
English · Original
Formal · Original
You have two numbers, and you decide to apply a special addition technique on them: you convert both numbers to quaternary (base 4), and add each digit pair separately. If this results in a number greater than or equal to 4, you subtract four from the result. For example, if you had the numbers 322312 and 213200 in base 4, the result would be 131112. Given two numbers in base ten, apply this technique on them, and convert the result back into base 10. The first line of input contains a single positive integer $a$. The second line of input contains a single positive integer $b$. Print the result of applying the operation described above on $a$ and $b$, converted back into decimal (Base 10). ## Input The first line of input contains a single positive integer $a$.The second line of input contains a single positive integer $b$. ## Output Print the result of applying the operation described above on $a$ and $b$, converted back into decimal (Base 10). [samples]
**Definitions** Let $ a, b \in \mathbb{Z}^+ $ be the two input integers. Let $ A = (a_{m-1}, \dots, a_0)_4 $ and $ B = (b_{m-1}, \dots, b_0)_4 $ be the quaternary representations of $ a $ and $ b $, padded with leading zeros to equal length $ m = \max(\lfloor \log_4 a \rfloor + 1, \lfloor \log_4 b \rfloor + 1) $. **Operation** Define digit-wise addition modulo 4: For each digit position $ i \in \{0, \dots, m-1\} $, compute $$ c_i = (a_i + b_i) \bmod 4 $$ Let $ C = (c_{m-1}, \dots, c_0)_4 $ be the resulting quaternary number. **Objective** Compute and output the decimal value of $ C $: $$ \sum_{i=0}^{m-1} c_i \cdot 4^i $$
API Response (JSON)
{
  "problem": {
    "name": "188. Quaternary Addition",
    "description": {
      "content": "You have two numbers, and you decide to apply a special addition technique on them: you convert both numbers to quaternary (base 4), and add each digit pair separately. If this results in a number gre",
      "description_type": "Markdown"
    },
    "platform": "Codeforces",
    "limit": {
      "time_limit": 1000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "CF10269188"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "You have two numbers, and you decide to apply a special addition technique on them: you convert both numbers to quaternary (base 4), and add each digit pair separately. If this results in a number gre...",
      "is_translate": false,
      "language": "English"
    },
    {
      "statement_type": "Markdown",
      "content": "**Definitions**  \nLet $ a, b \\in \\mathbb{Z}^+ $ be the two input integers.  \nLet $ A = (a_{m-1}, \\dots, a_0)_4 $ and $ B = (b_{m-1}, \\dots, b_0)_4 $ be the quaternary representations of $ a $ and $ b ...",
      "is_translate": false,
      "language": "Formal"
    }
  ]
}
Full JSON Raw Segments