Hobbits' Party

Description

Everyone knows that hobbits love to organize all sorts of parties and celebrations. There are n hobbits living in the Shire. They decided to organize the Greatest Party (GP) that would last for several days. Next day the hobbits wrote a guest list, some non-empty set containing all the inhabitants of the Shire. To ensure that everybody enjoy themselves and nobody gets bored, for any two days (say, days A and B) of the GP there existed at least one hobbit, invited to come on day A and on day B. However, to ensure that nobody has a row, for any three different days A, B, C there shouldn't be a hobbit invited on days A, B and C. The Shire inhabitants are keen on keeping the GP going for as long as possible. Your task is given number n, to indicate the GP's maximum duration and the guest lists for each day.

Input

The first line contains an integer n (3 ≤ n ≤ 10000), representing the number of hobbits.

Output

In the first output line print a number k — the maximum duration of GP in days. Then on k lines print the guest lists, (the guests should be separated by spaces). Print each guest list on the single line. Each list can contain an arbitrary positive number of hobbits. The hobbits are numbered with integers from 1 to n.

Sample Input

Input
4
Output
3
1 2 
1 3 
2 3 
Input
5
Output
3
1 2 
1 3 
2 3 


#include<stdio.h>
int main()
{
    int n,m,k1,k2,i,j,b[150][150];
    while(scanf("%d",&n)!=EOF)
    {
        for(m=3;m<=150;m++)
        {
            if(2*n<m*(m+1))
                break;
        }
        printf("%d\n",m);
        n=m*(m-1)/2;h
        k1=1;
        k2=1;
        for(i=1;i<=m;i++)
        {
            for(j=i;j<=m-1;j++)
            {
                    b[i][j]=k1++;
            }
        }
        for(j=1;j<=m-1;j++)
        {
            for(i=j+1;i<=m;i++)
            {
                    b[i][j]=k2++;
            }
        }
        for(i=1;i<=m;i++)
        {
            for(j=1;j<=m-1;j++)
                printf("%d ",b[i][j]);
            printf("\n");
        }
    }
    return 0;
}



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值