#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 200001, MAX_K = 5;
int N, K;
int num[MAX_N][MAX_K];
long long sum[MAX_N][MAX_K];
vector<int> adj[MAX_N];
vector<int> info_num[MAX_N][MAX_K];
vector<long long> info_sum[MAX_N][MAX_K];
void dfs1(int v, int dad) {
  num[v][0] = 1;
  for (int i = 0; i < (int)adj[v].size(); i++) {
    int u = adj[v][i];
    if (u == dad) continue;
    dfs1(u, v);
    for (int k = 0; k < K; k++) {
      info_num[v][k][i] = num[u][(k + K - 1) % K];
      info_sum[v][k][i] = sum[u][(k + K - 1) % K];
    }
    info_sum[v][(K == 1) ? 0 : 1][i] += (long long)num[u][0];
    for (int k = 0; k < K; k++) {
      num[v][k] += info_num[v][k][i];
      sum[v][k] += info_sum[v][k][i];
    }
  }
}
void dfs2(int v, int idx, int dad) {
  if (dad != v) {
    for (int i = 0; i < K; i++) {
      num[v][i] +=
          num[dad][(i + K - 1) % K] - info_num[dad][(i + K - 1) % K][idx];
      sum[v][i] +=
          sum[dad][(i + K - 1) % K] - info_sum[dad][(i + K - 1) % K][idx];
    }
    sum[v][(K == 1) ? 0 : 1] +=
        (long long)(num[dad][0] - info_num[dad][0][idx]);
  }
  for (int i = 0; i < (int)adj[v].size(); i++) {
    int u = adj[v][i];
    if (u == dad) continue;
    dfs2(u, i, v);
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> N >> K;
  for (int i = 0; i < N - 1; i++) {
    int A, B;
    cin >> A >> B;
    adj[A].push_back(B);
    adj[B].push_back(A);
  }
  for (int i = 1; i <= N; i++) {
    for (int j = 0; j < K; j++) {
      info_num[i][j].resize(adj[i].size());
      info_sum[i][j].resize(adj[i].size());
    }
  }
  dfs1(1, 1);
  dfs2(1, 0, 1);
  long long ans = 0;
  for (int i = 1; i <= N; i++)
    for (int j = 0; j < K; j++) ans += sum[i][j];
  cout << ans / 2LL << "\n";
  return 0;
}
