#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline T sqr(T a) {
  return a * a;
};
const double pi = acos(-1.0);
const int INF = INT_MAX;
const long long LLINF = LLONG_MAX;
const int MAX_N = 2e5 + 10;
vector<int> G[MAX_N];
int count_subtree[MAX_N][5];
int total_subtree[MAX_N];
long long ans;
int n, k;
int subtract(int a, int b) { return ((a - b) % k + k) % k; }
void dfs(int v, int p, int d) {
  count_subtree[v][d % k] = total_subtree[v] = 1;
  for (int u : G[v])
    if (u != p) {
      dfs(u, v, d + 1);
      for (int i = 0; i < k; i++) {
        for (int j = 0; j < k; j++) {
          int reminder = subtract(i + j, 2 * d);
          int needs = subtract(k, reminder);
          ans += (long long)needs * count_subtree[v][i] * count_subtree[u][j];
        }
      }
      for (int i = 0; i < k; i++) count_subtree[v][i] += count_subtree[u][i];
      total_subtree[v] += total_subtree[u];
    }
  ans += (long long)total_subtree[v] * (n - total_subtree[v]);
}
int main() {
  scanf("%d%d", &n, &k);
  for (int i = 1; i < n; i++) {
    int a, b;
    scanf("%d%d", &a, &b);
    G[a].push_back(b);
    G[b].push_back(a);
  }
  dfs(1, -1, 0);
  cout << (ans / k) << endl;
  return 0;
}
