Mrs. Smith is trying to contact her husband, John Smith, but she forgot the secret phone number!

The only thing Mrs. Smith remembered was that any permutation of nn can be a secret phone number. Only those permutations that minimize secret value might be the phone of her husband.

The sequence of nn integers is called a permutation if it contains all integers from 11 to nn exactly once.

The secret value of a phone number is defined as the sum of the length of the longest increasing subsequence (LIS) and length of the longest decreasing subsequence (LDS).

A subsequence ai1,ai2,…,aikai1,ai2,…,aik where 1≤i1<i2<…<ik≤n1≤i1<i2<…<ik≤n is called increasing if ai1<ai2<ai3<…<aikai1<ai2<ai3<…<aik. If ai1>ai2>ai3>…>aikai1>ai2>ai3>…>aik, a subsequence is called decreasing. An increasing/decreasing subsequence is called longest if it has maximum length among all increasing/decreasing subsequences.

For example, if there is a permutation [6,4,1,7,2,3,5][6,4,1,7,2,3,5], LIS of this permutation will be [1,2,3,5][1,2,3,5], so the length of LIS is equal to 44. LDScan be [6,4,1][6,4,1], [6,4,2][6,4,2], or [6,4,3][6,4,3], so the length of LDS is 33.

Note, the lengths of LIS and LDS can be different.

So please help Mrs. Smith to find a permutation that gives a minimum sum of lengths of LIS and LDS.

Input

The only line contains one integer nn (1≤n≤1051≤n≤105) — the length of permutation that you need to build.

Output

Print a permutation that gives a minimum sum of lengths of LIS and LDS.

If there are multiple answers, print any.

Examples
input

Copy
4
output

Copy
3 4 1 2
input

Copy
2
output

Copy
2 1
Note

In the first sample, you can build a permutation [3,4,1,2][3,4,1,2]. LIS is [3,4][3,4] (or [1,2][1,2]), so the length of LIS is equal to 22. LDS can be ony of [3,1][3,1], [4,2][4,2], [3,2][3,2], or [4,1][4,1]. The length of LDS is also equal to 22. The sum is equal to 44. Note that [3,4,1,2][3,4,1,2] is not the only permutation that is valid.

In the second sample, you can build a permutation [2,1][2,1]. LIS is [1][1] (or [2][2]), so the length of LIS is equal to 11. LDS is [2,1][2,1], so the length of LDS is equal to 22. The sum is equal to 33. Note that permutation [1,2][1,2] is also valid.

题意:给定N,输出一个N的排列,满足其LIS+LDS最小。

思路:当时猜到了是根号倒序排序,但是写WA了。 应该是有什么证明的,不过不难想。

#include<bits/stdc++.h>
using namespace std;
const int maxn=;
int a[maxn];
int main()
{
int N,tN,i,j;
scanf("%d",&N); tN=sqrt(N); int p=N;
for(i=;i<=N;i+=tN){
for(j=min(N,i+tN-);j>=i;j--) a[j]=p--;
}
for(i=;i<=N;i++) printf("%d ",a[i]);
return ;
}

CodeForces - 1017 C. The Phone Number(数学)的更多相关文章

  1. Educational Codeforces Round 7 D. Optimal Number Permutation 构造题

    D. Optimal Number Permutation 题目连接: http://www.codeforces.com/contest/622/problem/D Description You ...

  2. Codeforces 599D Spongebob and Squares(数学)

    D. Spongebob and Squares Spongebob is already tired trying to reason his weird actions and calculati ...

  3. Codeforces Gym 100425A Luggage Distribution 二分 数学

    A - Luggage DistributionTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/c ...

  4. 【 CodeForces - 392C】 Yet Another Number Sequence (二项式展开+矩阵加速)

    Yet Another Number Sequence Description Everyone knows what the Fibonacci sequence is. This sequence ...

  5. CodeForces 546 D. Soldier and Number Game(素数有关)

    Description Two soldiers are playing a game. At the beginning first of them chooses a positive integ ...

  6. Codeforces 839D Winter is here【数学:容斥原理】

    D. Winter is here time limit per test:3 seconds memory limit per test:256 megabytes input:standard i ...

  7. A. Little C Loves 3 I Codeforces Round #511 (Div. 2) 【数学】

    题目: Little C loves number «3» very much. He loves all things about it. Now he has a positive integer ...

  8. 【codeforces 514A】Chewbaсca and Number

    [题目链接]:http://codeforces.com/contest/514/problem/A [题意] 允许你把每个数字翻转 ->x变成9-x 然后问你能够变成的最小的数字是什么; 不能 ...

  9. HDU 1018 Big Number 数学题解

    Problem Description In many applications very large integers numbers are required. Some of these app ...

随机推荐

  1. Java线程面试题:设计四个线程,其中两个线程每次对 j 加 1,另外两个每次对 j 减 1,程序如下。

    package thread; /** * Java线程面试题 * @author zhongfg * @date 2015-06-16 */ public class ThreadInterview ...

  2. 一个手动备份MySQL数据库的脚本

    #!/bin/bash username=root hostname=localhost password=root mysql -u$username -h$hostname -p$password ...

  3. 二、Android应用的界面编程(六)ProgressBar及其子类[SeekBar、RatingBar]er

    通常用于向用户显示某个耗时操作完成的百分比.Android支持几种风格的进度条,通过style属性可以为ProgressBar指定风格.该属性支持如下几个属性值. # @android:style/W ...

  4. 【BZOJ4010】[HNOI2015]菜肴制作 拓扑排序

    [BZOJ4010][HNOI2015]菜肴制作 Description 知名美食家小 A被邀请至ATM 大酒店,为其品评菜肴. ATM 酒店为小 A 准备了 N 道菜肴,酒店按照为菜肴预估的质量从高 ...

  5. java 基于tomcat的数据源案例

    1.在context中定义数据源 <?xml version="1.0" encoding="UTF-8"?> <Context path=& ...

  6. js绑定键盘enter事件

    js写法: document.onkeydown = function(event){ var event=document.all?window.event:event; if((event.key ...

  7. 从内存中加载并启动一个exe

    windows似乎只提供了一种启动进程的方法:即必须从一个可执行文件中加载并启动.而下面这段代码就是提供一种可以直接从内存中启动一个exe的变通办法.用途嘛, 也许可以用来保护你的exe,你可以对要保 ...

  8. 我的Android进阶之旅------>Android中android:windowSoftInputMode的用法

    面试题:如何在显示某个Activity时立即弹出软键盘? 答案:在AndroidManifest.xml文件中设置<activity>标签的android:windowSoftInputM ...

  9. Unknown Entity namespace alias 'BaseMemberBundle'.

    $em = $this->getDoctrine()->getManager('member');//要记得写上member $repo = $em->getRepository(' ...

  10. rest-client restclient get post写法

    get url = "https://api.weixin.qq.com/sns/jscode2session" data = { appid: "××××", ...