094. Computer Love

Codeforces
IDCF10269094
Time1000ms
Memory256MB
Difficulty
English · Original
Formal · Original
Computer Love You love your computer, and you want to give it a present: a large integer. However, your computer especially loves powers of two. Given two numbers $x$ and $y$, find the largest power of two between $x$ and $y$, i.e. find the largest number $n$ such that $x$ <= $n$ <= $y$, and $n$ is a power of two. The only line of input contains two space-separated integers $x$ and $y$: the lower and upper bounds of the range described in the problems statement. The values are inclusive, i.e. $x$ and $y$ could potentially be valid answers if they were powers of two. Output a single integer $n$: the largest power of two such that $x$ <= $n$ <= $y$. If there aren't any powers of two between $x$ and $y$, output $-1$. The answer is guaranteed to be within the bounds of 32-bit signed integers. ## Input The only line of input contains two space-separated integers $x$ and $y$: the lower and upper bounds of the range described in the problems statement. The values are inclusive, i.e. $x$ and $y$ could potentially be valid answers if they were powers of two. ## Output Output a single integer $n$: the largest power of two such that $x$ <= $n$ <= $y$. If there aren't any powers of two between $x$ and $y$, output $-1$. The answer is guaranteed to be within the bounds of 32-bit signed integers. [samples]
**Definitions** Let $ x, y \in \mathbb{Z} $ be the inclusive lower and upper bounds of the range. Let $ P = \{ 2^k \mid k \in \mathbb{Z},\, 2^k \geq 0 \} $ be the set of non-negative powers of two. **Constraints** $ x \leq y $, and $ x, y $ are within the bounds of 32-bit signed integers. **Objective** Find the largest $ n \in P $ such that $ x \leq n \leq y $. If no such $ n $ exists, output $ -1 $.
API Response (JSON)
{
  "problem": {
    "name": "094. Computer Love",
    "description": {
      "content": "Computer Love You love your computer, and you want to give it a present: a large integer. However, your computer especially loves powers of two. Given two numbers $x$ and $y$, find the largest power ",
      "description_type": "Markdown"
    },
    "platform": "Codeforces",
    "limit": {
      "time_limit": 1000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "CF10269094"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "Computer Love\n\nYou love your computer, and you want to give it a present: a large integer. However, your computer especially loves powers of two. Given two numbers $x$ and $y$, find the largest power ...",
      "is_translate": false,
      "language": "English"
    },
    {
      "statement_type": "Markdown",
      "content": "**Definitions**  \nLet $ x, y \\in \\mathbb{Z} $ be the inclusive lower and upper bounds of the range.  \nLet $ P = \\{ 2^k \\mid k \\in \\mathbb{Z},\\, 2^k \\geq 0 \\} $ be the set of non-negative powers of two...",
      "is_translate": false,
      "language": "Formal"
    }
  ]
}
Full JSON Raw Segments