CF286B.Shifting

提高+/省选-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

John Doe has found the beautiful permutation formula.

Let's take permutation p = _p_1, _p_2, ..., p__n. Let's define transformation f of this permutation:

where k (k > 1) is an integer, the transformation parameter, r is such maximum integer that rk ≤ n. If rk = n, then elements p__rk + 1, p__rk + 2 and so on are omitted. In other words, the described transformation of permutation p cyclically shifts to the left each consecutive block of length k and the last block with the length equal to the remainder after dividing n by k.

John Doe thinks that permutation f(f( ... f(p = [1, 2, ..., n], 2) ... , n - 1), n) is beautiful. Unfortunately, he cannot quickly find the beautiful permutation he's interested in. That's why he asked you to help him.

Your task is to find a beautiful permutation for the given n. For clarifications, see the notes to the third sample.

约翰·多伊尔发现了一个优美的排列公式。

考虑一个排列 $ p = p_1, p_2, \dots, p_n $。我们定义该排列的变换 $ f $ 如下:

其中 $ k (( k > 1 )是一个整数,称为变换参数;)是一个整数,称为变换参数; r $ 是满足 $ rk \le n $ 的最大整数。若 $ rk = n $,则元素 $ p_{rk+1}, p_{rk+2}, \dots $ 被省略。换言之,上述对排列 $ p $ 的变换,是将每个长度为 $ k $ 的连续块向左循环移位,而最后一块的长度等于 $ n $ 除以 $ k $ 的余数。

约翰·多伊尔认为排列

f(f(…f(p=[1,2,…,n], 2)…, n−1), n)f(f(\dots f(p = [1, 2, \dots, n],\, 2)\dots,\, n-1),\, n)

是优美的。遗憾的是,他无法快速求出自己感兴趣的优美排列。因此,他请你帮忙。

你的任务是:对给定的 $ n $,求出对应的优美排列。具体说明请参见第三个样例的注释。

输入格式

A single line contains integer n (2 ≤ n ≤ 106).

一行包含一个整数 nn(2 ≤ n ≤ 1062 \leq n \leq 10^6)。

输出格式

Print n distinct space-separated integers from 1 to n — a beautiful permutation of size n.

输出 n 个互不相同的、以空格分隔的整数(取值范围为 1 到 n)——即一个大小为 n 的优美排列。

输入输出样例

  • 输入#1

    2

    输出#1

    2 1
  • 输入#2

    3

    输出#2

    1 3 2
  • 输入#3

    4

    输出#3

    4 2 3 1

说明/提示

A note to the third test sample:

  • f([1, 2, 3, 4], 2) = [2, 1, 4, 3]
  • f([2, 1, 4, 3], 3) = [1, 4, 2, 3]
  • f([1, 4, 2, 3], 4) = [4, 2, 3, 1]

第三个测试样例的说明:

  • f([1, 2, 3, 4], 2) = [2, 1, 4, 3]f([1, 2, 3, 4], 2) = [2, 1, 4, 3]
  • f([2, 1, 4, 3], 3) = [1, 4, 2, 3]f([2, 1, 4, 3], 3) = [1, 4, 2, 3]
  • f([1, 4, 2, 3], 4) = [4, 2, 3, 1]f([1, 4, 2, 3], 4) = [4, 2, 3, 1]

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

首页