John Doe has found the beautiful permutation formula.

Let's take permutation p = p1, p2, ..., pn. 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 prk + 1, prk + 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.

Input

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

Output

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

Examples
Input
2
Output
2 1 
Input
3
Output
1 3 2 
Input
4
Output
4 2 3 1 
Note

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]

在每次变换的时候,都是取一个长度是t的区间,然后把区间的第一个元素放末尾

那么只要每次把所有这样长度为t的区间的a[kt+1]放到a[kt+t+1]即可。

比如样例的变换:

1 2 3 4 0 0 0

0 2 1 4 3 0 0

0 0 1 4 2 3 0

0 0 0 4 2 3 1

这样每次元素在数组当中的位置都会往后移一位,但是总长度还是n

 #include<cstdio>
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<queue>
#include<deque>
#include<set>
#include<map>
#include<ctime>
#define LL long long
#define inf 0x7ffffff
#define pa pair<int,int>
#define mkp(a,b) make_pair(a,b)
#define pi 3.1415926535897932384626433832795028841971
using namespace std;
inline LL read()
{
LL x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
int n;
int a[];
int main()
{
while (~scanf("%d",&n))
{
for (int i=;i<=n;i++)a[i]=i;
for (int k=;k<=n;k++)
{
int ed=n+k-,rp=n/k+(n%k!=);
for (int t=k-+(rp-)*k;t>=k-;t-=k)
{
swap(a[ed],a[t]);
ed=t;
}
}
for (int i=n;i<=*n-;i++)printf("%d ",a[i]);
puts("");
}
}

cf 287D

cf287D Shifting的更多相关文章

  1. Level shifting a +/- 2.5V signal to 0 - 5V

    Google : Op-Amp Level Shifter Level shifting a +/- 2.5V signal to 0 - 5V I have a front end module t ...

  2. [LeetCode] Shifting Letters 漂移字母

    We have a string S of lowercase letters, and an integer array shifts. Call the shift of a letter, th ...

  3. [Swift]LeetCode848. 字母移位 | Shifting Letters

    We have a string S of lowercase letters, and an integer array shifts. Call the shift of a letter, th ...

  4. Codeforces 286B Shifting (看题解)

    Shifting 感觉这题被智力打击了.. 刚开始我想的是对于每个位置我们可以暴力找出最后的位置在哪里. 因为对于当前位置p, 在进行第x步操作时, 如果p % x == 1 则 p = p + x ...

  5. XBee Level Shifting

    http://www.faludi.com/bwsn/xbee-level-shifting/ The XBee communication (RX/TX) pins definitely opera ...

  6. LeetCode 848. Shifting Letters

    原题链接在这里:https://leetcode.com/problems/shifting-letters/ 题目: We have a string S of lowercase letters, ...

  7. 848.Shifting Letters——weekly contest 87

    848. Shifting Letters 题目链接:https://leetcode.com/problems/shifting-letters/description/ 思路:O(N^2)复杂度过 ...

  8. 《Learning to warm up cold Item Embeddings for Cold-start Recommendation with Meta Scaling and Shifting Networks》论文阅读

    <Learning to warm up cold Item Embeddings for Cold-start Recommendation with Meta Scaling and Shi ...

  9. 【LeetCode】848. Shifting Letters 解题报告(Python)

    [LeetCode]848. Shifting Letters 解题报告(Python) 标签(空格分隔): LeetCode 作者: 负雪明烛 id: fuxuemingzhu 个人博客: http ...

随机推荐

  1. Redis学习笔记(一)五种数据类型

    1.字符串(String) 基本操作:SET(设置).GET(获取).DEL(删除)其他操作传送门 root@localhost:~# redis-cli > set msg hello OK ...

  2. 10个优秀的移动Web应用开发框架

    在最近几年里,移动互联网高速发展.市场潜力巨大.继计算机.互联网之后,移动互联网正掀起第三次信息技术革命的浪潮,新技术.新应用不断涌现.今天这篇文章向大家推荐10大优秀的移动Web开发框架,帮助开发者 ...

  3. DataModel doesn't have preference values

    mahout和hadoop实现简单的智能推荐系统的时候,出现了一下几个方面的错误 DataModel doesn't have preference values 意思是DataModel中没有找到初 ...

  4. Navicat连接Oracle详细教程

    Navicat Premium算是比较好的一个可视化数据库管理工具了,短小精悍,一个工具解决三种数据库的连接问题,真正做到了集成管理,对MySQL,SQLServer而言,连接比较简单,就不赘述了,现 ...

  5. webpack打包性能分析

    1. 如何定位webpack打包速度慢的原因 首先需要定位webpack打包速度慢的原因,才能因地制宜采取合适的方案,我们可以在终端输入: webpack --profile --json > ...

  6. 二分查找 && 三分查找

    LeetCode34. Find First and Last Position of Element in Sorted Array 题意:找出指定元素出现的范围,Ologn 思路:两次二分 cla ...

  7. 项目中多条数据保存的json实例

    //js代码function checkCode(num){ var typeid = $("#typeid").val(); if(typeid == "") ...

  8. shell脚本,每5个字符之间插入"|",行末不插入“|”。

    文本aaaaabbbbbcccccdddd eeeeefffffkkkkkvvvv nnnnnggggg 希望得到的结果如下: aaaaa|bbbbb|ccccc|dddd eeeee|fffff|k ...

  9. The eleven Day

    库操作 一 系统数据库 information_schema: 虚拟库,不占用磁盘空间,存储的是数据库启动后的一些参数,如用户表信息.列信息.权限信息.字符信息等 performance_schema ...

  10. styled-components

    参考: http://www.alloyteam.com/2017/05/guide-styled-components/ https://medium.com/styled-components/g ...