145. Star Wars

Codeforces
IDCF10269145
Time1000ms
Memory256MB
Difficulty
English · Original
Formal · Original
You've traveled across a galaxy far, far away, and you land on a planet with two different alien species. Each alien species counts numbers in a different base. Aliens of the first species count numbers using base $a$, and aliens of the second species count numbers using base $b$. The base used by most humans is decimal, base 10. The two alien species are about to start a war, because they cannot properly communicate in numbers. Your task is to convert a number from the first alien species, in base $a$, into base $b$, in order to avert the impending alien war. The first line of input contains two integers $a$ and $b$ less than or equal to 10: the number base used by the first alien species, and the number base used by the second alien species, respectively. The second line of input contains a single integer $n$ in base $a$. Output $m$: the given integer, converted from base $a$ to base $b$. ## Input The first line of input contains two integers $a$ and $b$ less than or equal to 10: the number base used by the first alien species, and the number base used by the second alien species, respectively.The second line of input contains a single integer $n$ in base $a$. ## Output Output $m$: the given integer, converted from base $a$ to base $b$. [samples]
**Definitions** Let $ a, b \in \mathbb{Z} $ with $ 2 \leq a, b \leq 10 $ be the source and target bases, respectively. Let $ n $ be a non-negative integer represented in base $ a $ as a string of digits $ d_k d_{k-1} \dots d_0 $, where each $ d_i \in \{0, 1, \dots, a-1\} $. **Constraints** 1. $ 2 \leq a \leq 10 $ 2. $ 2 \leq b \leq 10 $ 3. $ n $ is a valid base-$ a $ numeral (no leading zeros unless $ n = 0 $) **Objective** Convert $ n $ from base $ a $ to base $ b $: Let $ N = \sum_{i=0}^{k} d_i \cdot a^i $ be the decimal value of $ n $. Output the base-$ b $ representation of $ N $ as a string of digits $ m = e_\ell e_{\ell-1} \dots e_0 $, where $ N = \sum_{j=0}^{\ell} e_j \cdot b^j $ and each $ e_j \in \{0, 1, \dots, b-1\} $.
API Response (JSON)
{
  "problem": {
    "name": "145. Star Wars",
    "description": {
      "content": "You've traveled across a galaxy far, far away, and you land on a planet with two different alien species. Each alien species counts numbers in a different base. Aliens of the first species count numbe",
      "description_type": "Markdown"
    },
    "platform": "Codeforces",
    "limit": {
      "time_limit": 1000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "CF10269145"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "You've traveled across a galaxy far, far away, and you land on a planet with two different alien species. Each alien species counts numbers in a different base. Aliens of the first species count numbe...",
      "is_translate": false,
      "language": "English"
    },
    {
      "statement_type": "Markdown",
      "content": "**Definitions**  \nLet $ a, b \\in \\mathbb{Z} $ with $ 2 \\leq a, b \\leq 10 $ be the source and target bases, respectively.  \nLet $ n $ be a non-negative integer represented in base $ a $ as a string of ...",
      "is_translate": false,
      "language": "Formal"
    }
  ]
}
Full JSON Raw Segments