#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 100;
int n, k;
long long ans;
vector<int> G[N];
long long dp[N][10];
long long subsz[N];
int Calc(int a, int b) { return (a - b + k) % k; }
void DFS(int cur, int p, int d) {
  dp[cur][d % k] += 1;
  int sz = G[cur].size();
  int v;
  subsz[cur] = 1;
  for (int i = 0; i < sz; i++) {
    v = G[cur][i];
    if (v != p) {
      DFS(v, cur, d + 1);
      subsz[cur] += subsz[v];
      for (int a = 0; a < k; a++) {
        for (int b = 0; b < k; b++) {
          int rem = Calc(a + b, 2 * d);
          int needs = Calc(k, rem);
          ans += needs * dp[cur][a] * dp[v][b];
        }
      }
      for (int a = 0; a < k; a++) dp[cur][a] += dp[v][a];
    }
  }
  ans += subsz[cur] * (n - subsz[cur]);
}
int main() {
  cin >> n >> k;
  int u, v;
  for (int i = 1; i < n; i++) {
    cin >> u >> v;
    G[u].push_back(v);
    G[v].push_back(u);
  }
  DFS(1, -1, 0);
  cout << ans / k;
  return 0;
}
