#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
const int N = 200005;
int n, k;
vector<int> ke[N];
int F[N][10];
long long res = 0, S[N];
void DFS(int u, int p) {
  F[u][0] = 1;
  for (int v : ke[u]) {
    if (v == p) continue;
    DFS(v, u);
    for (int i = 1; i <= k - 1; i++) F[u][i] += F[v][i - 1];
    F[u][0] += F[v][k - 1];
    S[u] += S[v] + F[v][0];
  }
}
void DFS2(int u, int p) {
  res += S[u];
  for (int v : ke[u]) {
    if (v == p) continue;
    for (int i = 1; i <= k - 1; i++) F[u][i] -= F[v][i - 1];
    F[u][0] -= F[v][k - 1];
    S[u] -= S[v] + F[v][0];
    for (int i = 1; i <= k - 1; i++) F[v][i] += F[u][i - 1];
    F[v][0] += F[u][k - 1];
    S[v] += S[u] + F[u][0];
    DFS2(v, u);
    for (int i = 1; i <= k - 1; i++) F[v][i] -= F[u][i - 1];
    F[v][0] -= F[u][k - 1];
    S[v] -= S[u] + F[u][0];
    for (int i = 1; i <= k - 1; i++) F[u][i] += F[v][i - 1];
    F[u][0] += F[v][k - 1];
    S[u] += S[v] + F[v][0];
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> k;
  for (int i = 1; i <= n - 1; i++) {
    int u, v;
    cin >> u >> v;
    ke[u].push_back(v);
    ke[v].push_back(u);
  }
  DFS(1, -1);
  DFS2(1, -1);
  cout << res / 2;
  return 0;
}
