#include <bits/stdc++.h>   template <typename Arg1>   void ZZ(const char* name, Arg1&& arg1) {     std::cout << name <<   =   << arg1 << std::endl;   }   template <typename Arg1, typename... Args>   void ZZ(const char* names, Arg1&& arg1, Args&&... args) {     const char* comma = strchr(names + 1,  , );     std::cout.write(names, comma - names) <<   =   << arg1;     ZZ(comma, args...);   }   using namespace std;   long long int to_ll(string& s) {     long long int i, ret = 0, p = 1;     for (i = (long long int)s.length() - 1; i >= 0; i--)       ret += (s[i] -  0 ) * p, p *= 10LL;     return ret;   }   long long int gcd(long long int x, long long int y) {     if (y == 0) return x;     return gcd(y, x % y);   }   long long int pwr(long long int base, long long int expo, long long int m) {     if (base == 0) return 0LL;     if (expo == 0) return (1LL % m);     if ((expo & 1) == 0) {       long long int temp = pwr(base, expo >> 1, m);       return (temp * temp) % m;     }     return ((base % m) * pwr(base, expo - 1, m)) % 1000000007;   }   vector<long long int> adj[200009];   long long int dp_down[200009][5], dp_up[200009][5], sz_down[200009][5],       sz_up[200009][5], p[200009], dp[200009][5], dp_sz[200009][5];   bool v_dp_down[200009][5], v_dp_up[200009][5], v_sz_down[200009][5],       v_sz_up[200009][5];   long long int n, k;   void dfs(long long int node, long long int parent) {     long long int i;     p[node] = parent;     for (i = 0; i < adj[node].size(); i++) {       long long int nxt = adj[node][i];       if (nxt == parent) continue;       dfs(nxt, node);     }   }   void dfs_sz_down(long long int node, long long int parent, long long int m) {     long long int i;     if (v_sz_down[node][m] == 1) return;     v_sz_down[node][m] = 1;     for (i = 0; i < adj[node].size(); i++) {       long long int nxt = adj[node][i];       long long int nxt_m = ((m - 1) % k + k) % k;       if (nxt == parent) continue;       dfs_sz_down(nxt, node, nxt_m);       sz_down[node][m] += sz_down[nxt][nxt_m];       dp_sz[node][nxt_m] += sz_down[nxt][nxt_m];     }     if (m == 0) sz_down[node][m]++;   }   void dfs_sz_up(long long int node, long long int parent, long long int m) {     if (v_sz_up[node][m] == 1) return;     v_sz_up[node][m] = 1;     if (m == 0) sz_up[node][m]++;     if (parent == -1) return;     long long int nxt_m = ((m - 1) % k + k) % k, i;     dfs_sz_up(parent, p[parent], nxt_m);     sz_up[node][m] += sz_up[parent][nxt_m];     sz_up[node][m] += dp_sz[parent][((m - 2) % k + k) % k];     sz_up[node][m] -= sz_down[node][((m - 2) % k + k) % k];   }   void dfs_up(long long int node, long long int parent, long long int m) {     if (v_dp_up[node][m] == 1) return;     v_dp_up[node][m] = 1;     if (parent == -1) return;     long long int nxt_m = ((m - 1) % k + k) % k, i;     dfs_up(parent, p[parent], nxt_m);     dp_up[node][m] += sz_up[parent][nxt_m] + dp_up[parent][nxt_m];     dp_up[node][m] += dp[parent][((m - 2) % k + k) % k];     dp_up[node][m] -= (2 * sz_down[node][((m - 2) % k + k) % k] +                        dp_down[node][((m - 2) % k + k) % k]);   }   void dfs_down(long long int node, long long int parent, long long int m) {     if (v_dp_down[node][m] == 1) return;     v_dp_down[node][m] = 1;     long long int i;     for (i = 0; i < adj[node].size(); i++) {       long long int nxt = adj[node][i];       long long int nxt_m = ((m - 1) % k + k) % k;       if (nxt == parent) continue;       dfs_down(nxt, node, nxt_m);       dp_down[node][m] += sz_down[nxt][nxt_m] + dp_down[nxt][nxt_m];       dp[node][nxt_m] += (2 * sz_down[nxt][nxt_m] + dp_down[nxt][nxt_m]);     }   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     ;     long long int i, j, x, y, ans = 0;     cin >> n >> k;     for (i = 0; i < n - 1; i++) {       cin >> x >> y;       adj[x].push_back(y);       adj[y].push_back(x);     }     dfs(1, -1);     for (i = 1; i <= n; i++)       for (j = 0; j < k; j++) dfs_sz_down(i, p[i], j);     for (i = 1; i <= n; i++)       for (j = 0; j < k; j++) dfs_sz_up(i, p[i], j);     for (i = 1; i <= n; i++)       for (j = 0; j < k; j++) dfs_down(i, p[i], j);     for (i = 1; i <= n; i++)       for (j = 0; j < k; j++) dfs_up(i, p[i], j);     for (j = 0; j < k; j++) {       for (i = 1; i <= n; i++) {         long long int total = dp_up[i][j] + dp_down[i][j];         long long int total_sz = sz_down[i][j] + sz_up[i][j];         if (j == 0) total_sz--;         long long int val = ((total - total_sz * j) / k);         if (j != 0) val += total_sz;         ans += val;       }     }     cout << ans / 2 <<   n ;     return 0;   }