C. Plus and Square Root

Codeforces
IDCF716C
Time2000ms
Memory256MB
Difficulty
constructive algorithmsmathnumber theory
English · Original
Chinese · Translation
Formal · Original
ZS the Coder is playing a game. There is a number displayed on the screen and there are two buttons, ' + ' (plus) and '' (square root). Initially, the number 2 is displayed on the screen. There are _n_ + 1 levels in the game and ZS the Coder start at the level 1. When ZS the Coder is at level _k_, he can : 1. _Press the ' + ' button_. This increases the number on the screen by exactly _k_. So, if the number on the screen was _x_, it becomes _x_ + _k_. 2. _Press the '' button_. Let the number on the screen be _x_. After pressing this button, the number becomes . After that, ZS the Coder levels up, so his current level becomes _k_ + 1. This button can only be pressed when _x_ is a **perfect square**, i.e. _x_ = _m_2 for some positive integer _m_. Additionally, after each move, if ZS the Coder is at level _k_, and the number on the screen is _m_, then **_m_ must be a multiple of _k_**. Note that this condition is only checked after performing the press. For example, if ZS the Coder is at level 4 and current number is 100, he presses the '' button and the number turns into 10. Note that at this moment, 10 is not divisible by 4, but this press is still valid, because after it, ZS the Coder is at level 5, and 10 is divisible by 5. ZS the Coder needs your help in beating the game — he wants to reach level _n_ + 1. In other words, he needs to press the '' button _n_ times. Help him determine the number of times he should press the ' + ' button before pressing the '' button at each level. Please note that ZS the Coder wants to find just any sequence of presses allowing him to reach level _n_ + 1, but not necessarily a sequence minimizing the number of presses. ## Input The first and only line of the input contains a single integer _n_ (1 ≤ _n_ ≤ 100 000), denoting that ZS the Coder wants to reach level _n_ + 1. ## Output Print _n_ non-negative integers, one per line. _i_\-th of them should be equal to the number of times that ZS the Coder needs to press the ' + ' button before pressing the '' button at level _i_. Each number in the output should not exceed 1018. However, the number on the screen **can be greater** than 1018. It is guaranteed that at least one solution exists. If there are multiple solutions, print any of them. [samples] ## Note In the first sample case: On the first level, ZS the Coder pressed the ' + ' button 14 times (and the number on screen is initially 2), so the number became 2 + 14·1 = 16. Then, ZS the Coder pressed the '' button, and the number became . After that, on the second level, ZS pressed the ' + ' button 16 times, so the number becomes 4 + 16·2 = 36. Then, ZS pressed the '' button, levelling up and changing the number into . After that, on the third level, ZS pressed the ' + ' button 46 times, so the number becomes 6 + 46·3 = 144. Then, ZS pressed the '' button, levelling up and changing the number into . Note that 12 is indeed divisible by 4, so ZS the Coder can reach level 4. Also, note that pressing the ' + ' button 10 times on the third level before levelling up does not work, because the number becomes 6 + 10·3 = 36, and when the '' button is pressed, the number becomes and ZS the Coder is at Level 4. However, 6 is not divisible by 4 now, so this is **not a valid solution.** In the second sample case: On the first level, ZS the Coder pressed the ' + ' button 999999999999999998 times (and the number on screen is initially 2), so the number became 2 + 999999999999999998·1 = 1018. Then, ZS the Coder pressed the '' button, and the number became . After that, on the second level, ZS pressed the ' + ' button 44500000000 times, so the number becomes 109 + 44500000000·2 = 9·1010. Then, ZS pressed the '' button, levelling up and changing the number into . Note that 300000 is a multiple of 3, so ZS the Coder can reach level 3.
ZS the Coder 正在玩一个游戏。屏幕上显示一个数字,有两个按钮:'#cf_span[ + ]'(加)和 ''(平方根)。最初,屏幕上显示的数字是 #cf_span[2]。游戏中共有 #cf_span[n + 1] 个等级,ZS the Coder 从第 #cf_span[1] 级开始。 当 ZS the Coder 处于第 #cf_span[k] 级时,他可以: 此外,每次操作后,如果 ZS the Coder 处于第 #cf_span[k] 级,且屏幕上的数字为 #cf_span[m],则 *#cf_span[m] 必须是 #cf_span[k] 的倍数*。请注意,此条件仅在执行按下操作后检查。例如,如果 ZS the Coder 处于第 #cf_span[4] 级,当前数字为 #cf_span[100],他按下 '' 按钮,数字变为 #cf_span[10]。注意此时 #cf_span[10] 不能被 #cf_span[4] 整除,但该操作仍然有效,因为在操作后 ZS the Coder 进入第 #cf_span[5] 级,而 #cf_span[10] 能被 #cf_span[5] 整除。 ZS the Coder 需要你的帮助来通关——他希望到达第 #cf_span[n + 1] 级。换句话说,他需要按下 '' 按钮 #cf_span[n] 次。请帮他确定在每一级按下 '' 按钮前,需要按下 '#cf_span[ + ]' 按钮多少次。 请注意,ZS the Coder 只需要找到任意一个能让他到达第 #cf_span[n + 1] 级的操作序列,而不一定是最少操作次数的序列。 输入仅包含一行,一个整数 #cf_span[n](#cf_span[1 ≤ n ≤ 100 000]),表示 ZS the Coder 想要到达第 #cf_span[n + 1] 级。 请输出 #cf_span[n] 个非负整数,每行一个。第 #cf_span[i] 个数应表示在第 #cf_span[i] 级按下 '' 按钮前,需要按下 '#cf_span[ + ]' 按钮的次数。每个输出的数不应超过 #cf_span[1018]。然而,屏幕上的数字 *可以大于* #cf_span[1018]。 保证至少存在一个解。如果有多个解,请输出任意一个。 在第一个样例中: 在第一级,ZS the Coder 按下了 '#cf_span[ + ]' 按钮 #cf_span[14] 次(屏幕初始数字为 #cf_span[2]),因此数字变为 #cf_span[2 + 14·1 = 16]。然后,ZS the Coder 按下了 '' 按钮,数字变为 。 之后,在第二级,ZS 按下了 '#cf_span[ + ]' 按钮 #cf_span[16] 次,因此数字变为 #cf_span[4 + 16·2 = 36]。然后,ZS 按下了 '' 按钮,升级并将数字变为 。 之后,在第三级,ZS 按下了 '#cf_span[ + ]' 按钮 #cf_span[46] 次,因此数字变为 #cf_span[6 + 46·3 = 144]。然后,ZS 按下了 '' 按钮,升级并将数字变为 。 注意 #cf_span[12] 确实能被 #cf_span[4] 整除,因此 ZS the Coder 可以到达第 #cf_span[4] 级。 另外,请注意,如果在第三级升级前只按了 #cf_span[10] 次 '#cf_span[ + ]' 按钮,数字会变成 #cf_span[6 + 10·3 = 36],按下 '' 按钮后数字变为 ,此时 ZS the Coder 处于第 #cf_span[4] 级。但此时 #cf_span[6] 不能被 #cf_span[4] 整除,因此这 *不是一个有效解*。 在第二个样例中: 在第一级,ZS the Coder 按下了 '#cf_span[ + ]' 按钮 #cf_span[999999999999999998] 次(屏幕初始数字为 #cf_span[2]),因此数字变为 #cf_span[2 + 999999999999999998·1 = 1018]。然后,ZS the Coder 按下了 '' 按钮,数字变为 。 之后,在第二级,ZS 按下了 '#cf_span[ + ]' 按钮 #cf_span[44500000000] 次,因此数字变为 #cf_span[109 + 44500000000·2 = 9·1010]。然后,ZS 按下了 '' 按钮,升级并将数字变为 。 注意 #cf_span[300000] 是 #cf_span[3] 的倍数,因此 ZS the Coder 可以到达第 #cf_span[3] 级。 ## Input 输入仅包含一行,一个整数 #cf_span[n](#cf_span[1 ≤ n ≤ 100 000]),表示 ZS the Coder 想要到达第 #cf_span[n + 1] 级。 ## Output 请输出 #cf_span[n] 个非负整数,每行一个。第 #cf_span[i] 个数应表示在第 #cf_span[i] 级按下 '' 按钮前,需要按下 '#cf_span[ + ]' 按钮的次数。每个输出的数不应超过 #cf_span[1018]。然而,屏幕上的数字 *可以大于* #cf_span[1018]。保证至少存在一个解。如果有多个解,请输出任意一个。 [samples] ## Note 在第一个样例中:在第一级,ZS the Coder 按下了 '#cf_span[ + ]' 按钮 #cf_span[14] 次(屏幕初始数字为 #cf_span[2]),因此数字变为 #cf_span[2 + 14·1 = 16]。然后,ZS the Coder 按下了 '' 按钮,数字变为 。之后,在第二级,ZS 按下了 '#cf_span[ + ]' 按钮 #cf_span[16] 次,因此数字变为 #cf_span[4 + 16·2 = 36]。然后,ZS 按下了 '' 按钮,升级并将数字变为 。之后,在第三级,ZS 按下了 '#cf_span[ + ]' 按钮 #cf_span[46] 次,因此数字变为 #cf_span[6 + 46·3 = 144]。然后,ZS 按下了 '' 按钮,升级并将数字变为 。注意 #cf_span[12] 确实能被 #cf_span[4] 整除,因此 ZS the Coder 可以到达第 #cf_span[4] 级。另外,请注意,如果在第三级升级前只按了 #cf_span[10] 次 '#cf_span[ + ]' 按钮,数字会变成 #cf_span[6 + 10·3 = 36],按下 '' 按钮后数字变为 ,此时 ZS the Coder 处于第 #cf_span[4] 级。但此时 #cf_span[6] 不能被 #cf_span[4] 整除,因此这 *不是一个有效解*。在第二个样例中:在第一级,ZS the Coder 按下了 '#cf_span[ + ]' 按钮 #cf_span[999999999999999998] 次(屏幕初始数字为 #cf_span[2]),因此数字变为 #cf_span[2 + 999999999999999998·1 = 1018]。然后,ZS the Coder 按下了 '' 按钮,数字变为 。之后,在第二级,ZS 按下了 '#cf_span[ + ]' 按钮 #cf_span[44500000000] 次,因此数字变为 #cf_span[109 + 44500000000·2 = 9·1010]。然后,ZS 按下了 '' 按钮,升级并将数字变为 。注意 #cf_span[300000] 是 #cf_span[3] 的倍数,因此 ZS the Coder 可以到达第 #cf_span[3] 级。
**Definitions** Let $ n \in \mathbb{Z} $, $ 1 \leq n \leq 100{,}000 $. Let $ x_0 = 2 $ be the initial number on the screen. For each level $ k \in \{1, 2, \dots, n\} $, let $ a_k \in \mathbb{Z}_{\geq 0} $ be the number of times the '+' button is pressed before pressing the '√' button at level $ k $. Let $ x_k $ denote the number on the screen after completing level $ k $ (i.e., after $ a_k $ additions and one square root). **Constraints** For each $ k \in \{1, \dots, n\} $: 1. Before pressing '√' at level $ k $, the number is $ x_{k-1} + a_k \cdot k $. 2. After pressing '√', the number becomes $ x_k = \sqrt{x_{k-1} + a_k \cdot k} $. 3. After the press at level $ k $, $ x_k $ must be an integer, and $ x_k \equiv 0 \pmod{k+1} $. **Objective** Find any sequence $ (a_1, a_2, \dots, a_n) $ of non-negative integers such that: $$ x_k = \sqrt{x_{k-1} + a_k \cdot k} \in \mathbb{Z}, \quad \text{and} \quad x_k \equiv 0 \pmod{k+1}, \quad \forall k \in \{1, \dots, n\} $$ with $ x_0 = 2 $.
Samples
Input #1
3
Output #1
14
16
46
Input #2
2
Output #2
999999999999999998
44500000000
Input #3
4
Output #3
2
17
46
97
API Response (JSON)
{
  "problem": {
    "name": "C. Plus and Square Root",
    "description": {
      "content": "ZS the Coder is playing a game. There is a number displayed on the screen and there are two buttons, ' + ' (plus) and '' (square root). Initially, the number 2 is displayed on the screen. There are _n",
      "description_type": "Markdown"
    },
    "platform": "Codeforces",
    "limit": {
      "time_limit": 2000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "CF716C"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "ZS the Coder is playing a game. There is a number displayed on the screen and there are two buttons, ' + ' (plus) and '' (square root). Initially, the number 2 is displayed on the screen. There are _n...",
      "is_translate": false,
      "language": "English"
    },
    {
      "statement_type": "Markdown",
      "content": "ZS the Coder 正在玩一个游戏。屏幕上显示一个数字,有两个按钮:'#cf_span[ + ]'(加)和 ''(平方根)。最初,屏幕上显示的数字是 #cf_span[2]。游戏中共有 #cf_span[n + 1] 个等级,ZS the Coder 从第 #cf_span[1] 级开始。\n\n当 ZS the Coder 处于第 #cf_span[k] 级时,他可以:\n\n此外,每次操作后,如...",
      "is_translate": true,
      "language": "Chinese"
    },
    {
      "statement_type": "Markdown",
      "content": "**Definitions**  \nLet $ n \\in \\mathbb{Z} $, $ 1 \\leq n \\leq 100{,}000 $.  \nLet $ x_0 = 2 $ be the initial number on the screen.  \nFor each level $ k \\in \\{1, 2, \\dots, n\\} $, let $ a_k \\in \\mathbb{Z}_...",
      "is_translate": false,
      "language": "Formal"
    }
  ]
}
Full JSON Raw Segments