#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
vector<int> g[N];
int n, k;
int cnt[N], sub[N][10];
long long int ans;
int modsub(int x, int y) { return (x - y + k) % k; }
void dfs(int x, int par, int d) {
  sub[x][d % k] = 1;
  cnt[x] = 1;
  for (int y : g[x]) {
    if (y == par) continue;
    dfs(y, x, d + 1);
    for (int i = 0; i < k; i++) {
      for (int j = 0; j < k; j++) {
        int lenrem = modsub(i + j, 2 * d);
        int need = modsub(k, lenrem);
        ans += (long long int)need * sub[x][i] * sub[y][j];
      }
    }
    for (int i = 0; i < k; i++) sub[x][i] += sub[y][i];
    cnt[x] += cnt[y];
  }
  ans += (long long int)cnt[x] * (n - cnt[x]);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int x, y;
  cin >> n >> k;
  for (int i = 1; i < n; i++) {
    cin >> x >> y;
    g[x].push_back(y);
    g[y].push_back(x);
  }
  dfs(1, -1, 0);
  cout << ans / k;
  return 0;
}
