D. High Load
time limit per test

2 seconds

memory limit per test

512 megabytes

input

standard input

output

standard output

Arkady needs your help again! This time he decided to build his own high-speed Internet exchange point. It should consist of n nodes connected with minimum possible number of wires into one network (a wire directly connects two nodes). Exactly k of the nodes should be exit-nodes, that means that each of them should be connected to exactly one other node of the network, while all other nodes should be connected to at least two nodes in order to increase the system stability.

Arkady wants to make the system as fast as possible, so he wants to minimize the maximum distance between two exit-nodes. The distance between two nodes is the number of wires a package needs to go through between those two nodes.

Help Arkady to find such a way to build the network that the distance between the two most distant exit-nodes is as small as possible.

Input

The first line contains two integers n and k (3 ≤ n ≤ 2·105, 2 ≤ k ≤ n - 1) — the total number of nodes and the number of exit-nodes.

Note that it is always possible to build at least one network with n nodes and k exit-nodes within the given constraints.

Output

In the first line print the minimum possible distance between the two most distant exit-nodes. In each of the next n - 1 lines print two integers: the ids of the nodes connected by a wire. The description of each wire should be printed exactly once. You can print wires and wires' ends in arbitrary order. The nodes should be numbered from 1 to n. Exit-nodes can have any ids.

If there are multiple answers, print any of them.

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

In the first example the only network is shown on the left picture.

In the second example one of optimal networks is shown on the right picture.

Exit-nodes are highlighted.

题意:构造一个n点的树只有k个叶子结点 使得相离最远的两个叶子结点的距离最小

题解:看过烟花吧,就是那个样子的。

 #pragma comment(linker, "/STACK:102400000,102400000")
#include <cstdio>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <cctype>
#include <map>
#include <set>
#include <queue>
#include <bitset>
#include <string>
#include <complex>
#define ll __int64
using namespace std;
int n,k;
int main()
{
scanf("%d %d",&n,&k);
if((n-)%k==)printf("%d\n",(n-)/k*);
else if((n-)%k==) printf("%d\n",(n-)/k*+);
else printf("%d\n",(n-)/k*+);
int exm=(n-)%k;
int re=;
for(int j=;j<=k;j++){
int jishu=(n-)/k;
if(exm>)
{
jishu++;
exm--;
}
printf("1 %d\n",re);
for(int i=;i<=jishu;i++){
printf("%d %d\n",re,re+);
re++;
}
re++;
}
return ;
}

最新文章

  1. Log4Net生成出现未引用错误解决方法
  2. Sicily 1151: 简单的马周游问题(DFS)
  3. 有border和没有border是两回事
  4. Python之路,Day1 - Python基础1
  5. nginx学习记录/2016.11.14
  6. EF Attach时已存在的处理方式
  7. Linux简单的常用命令——纯手打(慢慢积累)
  8. log4j的ConversionPattern参数的格式含义-转
  9. pdf Factory的设置
  10. How to running Job from a Form
  11. Apache Tomcat8必备知识
  12. jQuery数组处理函数
  13. poj 2774 Long Long Message,后缀数组,求最长公共子串 hdu1403
  14. Linux基础命令---tload显示系统负载
  15. AtCoder 瞎做
  16. iOS 弹出菜单UIMenuController的基本使用
  17. PHP从入门到精通(三)
  18. C#取得控制台应用程序的根目录方法 判断文件夹是否存在,不存在就创建
  19. python之旅:函数对象、函数嵌套、名称空间与作用域、装饰器
  20. voj 1754 spfa

热门文章

  1. day04 list tuple (补)
  2. 记录一次爬虫报错:Message: Failed to decode response from marionette
  3. 选题博客:北航iCourse课程信息平台
  4. Python学习 - 入门篇2(更新中)
  5. HDU 5666 Segment 数论+大数
  6. 关于解决java读取excel文件遇空行抛空指针的问题 !
  7. phaser2 微信小游戏入手
  8. Spring Cloud构建微服务架构
  9. ZOJ3067_Nim
  10. BZOJ3560 DZY Loves Math V(欧拉函数)