#include <bits/stdc++.h>
using namespace std;
int k;
class Solution {
  int n;
  long long ans = 0;
  struct DP {
    long long sum = 0;
    int cnt[5] = {0};
    DP() { cnt[0] = 1; }
    int count() const { return accumulate(cnt, cnt + k, 0); }
    DP &operator+=(const DP &oth) {
      sum += oth.sum;
      for (int i = 0; i < k; ++i) cnt[i] += oth.cnt[i];
      return *this;
    }
    void shift() {
      rotate(cnt, cnt + k - 1, cnt + k);
      sum += cnt[0];
    }
    long long operator*(const DP &oth) {
      long long ret = sum * oth.count() + oth.sum * count();
      for (int i = 0; i < k; ++i) {
        for (int j = 0; j < k; ++j) {
          ret += 1ll * (i + j + k - 1) / k * cnt[i] * oth.cnt[j];
        }
      }
      return ret;
    }
  };
  vector<vector<int>> g;
  DP dfs(int u, int p) {
    DP ret;
    for (int v : g[u])
      if (v != p) {
        auto cur = dfs(v, u);
        ans += ret * cur;
        ret += cur;
      }
    ret.shift();
    return ret;
  }

 public:
  void run() {
    cin >> n >> k;
    g.resize(n);
    for (int i = 0; i < n - 1; ++i) {
      int a, b;
      cin >> a >> b;
      --a, --b;
      g[a].push_back(b), g[b].push_back(a);
    }
    auto ass = dfs(0, 0);
    cout << ans << '\n';
  }
};
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  Solution().run();
}
