#K4746. Minimum Direct Communications

    ID: 28203 Type: Default 1000ms 256MiB

Minimum Direct Communications

Minimum Direct Communications

In a network of n devices labeled from 1 to n, two devices can directly communicate if and only if their ID difference is at most k. Your task is to determine the minimum number of direct communications required such that every device can communicate with every other device, either directly or indirectly.

This can be mathematically formulated as finding the minimum number of connections needed to ensure the graph is connected when an edge exists between devices i and j if \(|i - j| \le k\). The answer is given by the formula:

[ \text{Answer} = \max(0, n - k)]

Note: It is assumed that \(n \ge 1\) and \(k \ge 1\). In the special case where \(n = 1\), no communication is needed.

inputFormat

The input consists of a single line containing two integers n and k separated by a space, where:

  • n: the number of devices
  • k: the maximum allowed ID difference for direct communication

outputFormat

Output a single integer, representing the minimum number of direct communications required.

## sample
4 1
3