CF1408F.Two Different

提高+/省选-

通过率:0%

时间限制:3.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

You are given an integer nn.

You should find a list of pairs (x1,y1)(x_1, y_1), (x2,y2)(x_2, y_2), ..., (xq,yq)(x_q, y_q) (1≤xi,yi≤n1 \leq x_i, y_i \leq n) satisfying the following condition.

Let's consider some function f:N×N→Nf: \mathbb{N} \times \mathbb{N} \to \mathbb{N} (we define N\mathbb{N} as the set of positive integers). In other words, ff is a function that returns a positive integer for a pair of positive integers.

Let's make an array a1,a2,…,ana_1, a_2, \ldots, a_n, where ai=ia_i = i initially.

You will perform qq operations, in ii-th of them you will:

  1. assign t=f(axi,ayi)t = f(a_{x_i}, a_{y_i}) (tt is a temporary variable, it is used only for the next two assignments);
  2. assign axi=ta_{x_i} = t;
  3. assign ayi=ta_{y_i} = t.

In other words, you need to simultaneously change axia_{x_i} and ayia_{y_i} to f(axi,ayi)f(a_{x_i}, a_{y_i}). Note that during this process f(p,q)f(p, q) is always the same for a fixed pair of pp and qq.

In the end, there should be at most two different numbers in the array aa.

It should be true for any function ff.

Find any possible list of pairs. The number of pairs should not exceed 5⋅1055 \cdot 10^5.

给你一个整数 nn。

你需要找到一个由若干对 (x1,y1)(x_1, y_1)、(x2,y2)(x_2, y_2)、…、(xq,yq)(x_q, y_q)(其中 1≤xi,yi≤n1 \leq x_i, y_i \leq n)组成的列表,满足如下条件:

考虑某个函数 f:N×N→Nf: \mathbb{N} \times \mathbb{N} \to \mathbb{N}(这里我们将 N\mathbb{N} 定义为正整数集合)。换言之,ff 是一个将正整数对映射为正整数的函数。

构造一个数组 a1,a2,…,ana_1, a_2, \ldots, a_n,初始时 ai=ia_i = i。

你将执行 qq 次操作;在第 ii 次操作中,你将:

  1. 令 t=f(axi,ayi)t = f(a_{x_i}, a_{y_i})(tt 是一个临时变量,仅用于接下来的两次赋值);
  2. 将 axia_{x_i} 赋值为 tt;
  3. 将 ayia_{y_i} 赋值为 tt。

换句话说,你需要同时将 axia_{x_i} 和 ayia_{y_i} 更新为 f(axi,ayi)f(a_{x_i}, a_{y_i})。注意:在整个过程中,对于固定的 pp 和 qq,f(p,q)f(p, q) 的值始终相同。

最终,数组 aa 中至多包含两个不同的数值。

该性质必须对任意函数 ff 均成立。

请找出任意一个满足条件的数对列表。数对总数不得超过 5⋅1055 \cdot 10^5。

输入格式

The single line contains a single integer nn (1≤n≤15 0001 \leq n \leq 15\,000).

单行包含一个整数 nn(1≤n≤15 0001 \leq n \leq 15\,000)。

输出格式

In the first line print qq (0≤q≤5⋅1050 \leq q \leq 5 \cdot 10^5) — the number of pairs.

In each of the next qq lines print two integers. In the ii-th line print xix_i, yiy_i (1≤xi,yi≤n1 \leq x_i, y_i \leq n).

The condition described in the statement should be satisfied.

If there exists multiple answers you can print any of them.

第一行输出 qq(0≤q≤5⋅1050 \leq q \leq 5 \cdot 10^5)—— 表示数对的个数。

接下来的 qq 行中,每行输出两个整数。第 ii 行输出 xix_i、yiy_i(1≤xi,yi≤n1 \leq x_i, y_i \leq n)。

题目描述中的条件必须满足。

若存在多个合法答案,输出任意一个即可。

输入输出样例

  • 输入#1

    3

    输出#1

    1
    1 2
  • 输入#2

    4

    输出#2

    2
    1 2
    3 4

说明/提示

In the first example, after performing the only operation the array aa will be [f(a1,a2),f(a1,a2),a3][f(a_1, a_2), f(a_1, a_2), a_3]. It will always have at most two different numbers.

In the second example, after performing two operations the array aa will be [f(a1,a2),f(a1,a2),f(a3,a4),f(a3,a4)][f(a_1, a_2), f(a_1, a_2), f(a_3, a_4), f(a_3, a_4)]. It will always have at most two different numbers.

在第一个例子中,执行唯一一次操作后,数组 aa 将变为 [f(a1,a2),f(a1,a2),a3][f(a_1, a_2), f(a_1, a_2), a_3]。该数组始终至多包含两个不同的数。

在第二个例子中,执行两次操作后,数组 aa 将变为 [f(a1,a2),f(a1,a2),f(a3,a4),f(a3,a4)][f(a_1, a_2), f(a_1, a_2), f(a_3, a_4), f(a_3, a_4)]。该数组始终至多包含两个不同的数。

输入解题思路,AI测评打分。不知道怎么写?

首页