#include <bits/stdc++.h>
using namespace std;
const int MAX = 1e5 + 10;
const int MAXN = 1e4 + 10;
const int MOD = 1e9 + 7;
const int inf = 1e9;
const double pi = acos(-1.0);
const double eps = 1e-6;
int dx[] = {0, -1, 0, 1};
int dy[] = {1, 0, -1, 0};
vector<int> V[200100];
unsigned long long F[200100], G[200100][10], cnt[200100], sum[200100];
int n, k;
void DFS(int x, int father) {
  cnt[x] = 1LL;
  G[x][0] = 1LL;
  for (int i = 0; i < V[x].size(); i++) {
    int t = V[x][i];
    if (t == father) continue;
    DFS(t, x);
    F[x] += F[t];
    F[x] += sum[x] * cnt[t] + sum[t] * cnt[x];
    for (int p = 0; p < k; p++)
      for (int q = 0; q < k; q++) {
        unsigned long long tmp = G[x][p] * G[t][q];
        if (p + q > k - 1) tmp *= 2LL;
        F[x] += tmp;
      }
    for (int j = 0; j < k; j++) G[x][(j + 1) % k] += G[t][j];
    sum[x] += sum[t];
    cnt[x] += cnt[t];
    sum[x] += G[t][k - 1];
  }
}
int main() {
  ios ::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> k;
  for (int i = 1; i <= n - 1; i++) {
    int u, v;
    cin >> u >> v;
    V[u].push_back(v);
    V[v].push_back(u);
  }
  unsigned long long res = 0;
  DFS(1, -1);
  cout << F[1];
  return 0;
}
