008. N-Dimensional Distance

Codeforces
IDCF10269008
Time1000ms
Memory256MB
Difficulty
English · Original
Formal · Original
Calculate the distance between two points of a specified dimension. The common distance formula still applies to higher dimensional points with a small modification. You will input two points and display the distance between them as you normally would with the distance formula. The n-dimensional distance formula can be expressed as $d (p, q) = sqrt((q_1 -p_1)^2 + (q_2 -p_2)^2 +... + (q_n -p_n)^2)$ or in other terms: $sqrt(sum_(i = 1)^n (q_i -p_i)^2) = d$ Remember that _math.sqrt_ will calculate the square root of a number (you also have to add the line _import math_ at the top of the program). The first line contains the dimension D between 2 and 500. Then, D test cases will follow. Each test case N will consist of two lines: the value of the first point, and the value of the second point, in the Nth dimension. Each of these values is an integer between -5000 and 5000, inclusive. A decimal number N representing the distance between the two points. Do not round your answer. ## Input The first line contains the dimension D between 2 and 500. Then, D test cases will follow.Each test case N will consist of two lines: the value of the first point, and the value of the second point, in the Nth dimension.Each of these values is an integer between -5000 and 5000, inclusive. ## Output A decimal number N representing the distance between the two points. Do not round your answer. [samples]
**Definitions** Let $ D \in \mathbb{Z} $ be the dimension, with $ 2 \leq D \leq 500 $. Let $ \mathbf{p} = (p_1, p_2, \dots, p_D) $ and $ \mathbf{q} = (q_1, q_2, \dots, q_D) $ be two points in $ \mathbb{R}^D $, where $ p_i, q_i \in \mathbb{Z} $ and $ -5000 \leq p_i, q_i \leq 5000 $ for all $ i \in \{1, \dots, D\} $. **Constraints** 1. $ 2 \leq D \leq 500 $ 2. $ p_i, q_i \in \mathbb{Z} $ and $ -5000 \leq p_i, q_i \leq 5000 $ for all $ i \in \{1, \dots, D\} $ **Objective** Compute the Euclidean distance $ d(\mathbf{p}, \mathbf{q}) $: $$ d(\mathbf{p}, \mathbf{q}) = \sqrt{\sum_{i=1}^{D} (q_i - p_i)^2} $$
API Response (JSON)
{
  "problem": {
    "name": "008. N-Dimensional Distance",
    "description": {
      "content": "Calculate the distance between two points of a specified dimension. The common distance formula still applies to higher dimensional points with a small modification. You will input two points and disp",
      "description_type": "Markdown"
    },
    "platform": "Codeforces",
    "limit": {
      "time_limit": 1000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "CF10269008"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "Calculate the distance between two points of a specified dimension. The common distance formula still applies to higher dimensional points with a small modification. You will input two points and disp...",
      "is_translate": false,
      "language": "English"
    },
    {
      "statement_type": "Markdown",
      "content": "**Definitions**  \nLet $ D \\in \\mathbb{Z} $ be the dimension, with $ 2 \\leq D \\leq 500 $.  \nLet $ \\mathbf{p} = (p_1, p_2, \\dots, p_D) $ and $ \\mathbf{q} = (q_1, q_2, \\dots, q_D) $ be two points in $ \\m...",
      "is_translate": false,
      "language": "Formal"
    }
  ]
}
Full JSON Raw Segments