#include <bits/stdc++.h>
using namespace std;
#define int long long
#define eb push_back
#define f first
#define s second
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);

const int N=2e5+5;
bool stat[N];
vector <int> g[N];
int n,k,depth[N],par[N],ans=0;
pair <int,int> dp[N][6];

void inline input() {
	cin>>n>>k;
	for(int i=0;i<n-1;i++) {
		int x,y;
		cin>>x>>y;
		g[x].eb(y);
		g[y].eb(x);
	}
}
void dfs(int u,int p ){
	depth[u]=depth[p]+1;
	par[u]=p;
	for(auto it:g[u]) {
		if(it==p) continue;
		dfs(it,u);
		for(int j=0;j<k;j++) {
			dp[u][j].f+=dp[it][j].f;
			dp[u][j].s+=dp[it][j].s;
		}
	}
	dp[u][depth[u]%k].f++;
	dp[u][depth[u]%k].s+=depth[u];
}
void bfs() {
	memset(stat,false,sizeof(stat));
	queue <int> q;
	q.push(1);
	while(!q.empty()) {
		int u=q.front();
		stat[u]=true;
		q.pop();
		if(u==1) {
			for(int i=0;i<k;i++) {
				//cout<<dp[u][i].f<<endl;
				ans+=(dp[u][i].s)/k;
				ans-=(dp[u][i].f*i)/k;
				if(i!=0) ans+=dp[u][i].f;
			}
			//cout<<ans<<endl;
		}
		else {
			pair<int,int> tmp[k];
			for(int i=0;i<k;i++) {
				tmp[(i+1)%k].f=dp[par[u]][i].f-dp[u][(i+(depth[par[u]]%k)+k)%k].f;
				tmp[(i+1)%k].s=dp[par[u]][i].s-dp[u][(i+(depth[par[u]]%k)+k)%k].s+(dp[u][(i+(depth[par[u]]%k)+k)%k].f*depth[par[u]]);
			}

			// if(u==3) {
			// 	for(int i=0;i<k;i++) cout<<tmp[i].s<<" ";
			// }
			for(int i=0;i<k;i++) tmp[i].s+=tmp[i].f;
			for(int i=0;i<k;i++) {
				tmp[(i-(depth[u]%k)+k)%k].f+=dp[u][i].f;
				tmp[(i-(depth[u]%k)+k)%k].s+=dp[u][i].s-dp[u][i].f*depth[u];
			}
			for(int i=0;i<k;i++) {
				ans+=(tmp[i].s)/k;
				ans-=(tmp[i].f*i)/k;
				if(i!=0)ans+=tmp[i].f;
			}
			for(int i=0;i<k;i++) dp[u][i]=tmp[i];
		//	cout<<u<<" "<<ans<<endl;
		}
		for(auto it:g[u]) {
			if(!stat[it]) {
				q.push(it);
				stat[it]=true;
			}
		}
	}
}
signed main() {
	IOS
	memset(dp,0,sizeof(dp));
	input();
	depth[0]=-1;
	dfs(1,0);
	bfs();
	cout<<ans/2;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define _for(i,a,b) for(int i=(a);i<(b);++i)
#define ms(a) memset(a,0,sizeof(a))
#define ms_inf(a) memset(a,0x3f,sizeof(a))
#define ms_ninf(a) memset(a,0xcf,sizeof(a))
#define pb push_back
#define mp make_pair
#define fast ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
const double eps = 1e-10;
const int maxn = 2e5+10;
const ll INF = 1e9;
int n,k;
ll ans=0;
ll cnt[maxn][5],sz[maxn];
vector<int>g[maxn];
void dfs(int u,int fa,int dep)
{
	cnt[u][dep%k]=sz[u]=1;
	for(auto v:g[u])
	{
		if(v==fa)continue;dfs(v,u,dep+1);
		_for(i,0,k)_for(j,0,k)
		{
			int bu=(k-(i+j)+2*dep)%k+k;bu%=k;
			ans+=cnt[u][i]*cnt[v][j]*bu;
		}
		_for(i,0,k)cnt[u][i]+=cnt[v][i];
		sz[u]+=sz[v];
		ans+=sz[v]*(n-sz[v]);
	}
}
int main()
{
	fast;cin>>n>>k;int a,b;_for(t,0,n-1)cin>>a>>b,g[a].pb(b),g[b].pb(a);
	dfs(1,0,0);
	assert(ans%k==0);
	cout<<ans/k;
}


#include "list"
#include <iostream>
#include <vector>
#include <fstream>
#include <map>
#include "algorithm"
#include <iomanip>
#include "cmath"
#include "set"
#include <climits>

using namespace std;
int n, m, k;
long long res = 0;
vector<vector<int>> g;
vector<vector<vector<long long>>> dp;
#pragma comment(linker, "/STACK:36777216")
void dfs(int v, int p){
    dp[v][0][0] = 1;
    for(auto x : g[v]){
        if(x==p)continue;
        dfs(x,v);
        for (int i = 0; i < k; ++i) {
            for (int j = 0; j < k; ++j) {
                if(dp[v][i][0] && dp[x][j][0]) {
                    res -= (i + j - 1 >= k) * dp[v][i][0] * dp[x][j][0];
                    res += (i + j - 1 < 0) * dp[v][i][0] * dp[x][j][0];
                    res += dp[v][i][1] * dp[x][j][0];
                    res += dp[v][i][0] * dp[x][j][1];
                }
            }
        }
        for (int i = 1; i < k; ++i) {
            dp[v][i-1][0] += dp[x][i][0];
            dp[v][i-1][1] += dp[x][i][1];
        }
        dp[v][k-1][0] += dp[x][0][0];
        dp[v][k-1][1] += dp[x][0][1] + dp[x][0][0];
    }
}
int main() {
    ios_base::sync_with_stdio(0);
    ifstream fin("coins.in");
    ofstream fout("coins.out");
    cin >> n >> k;
    m = n - 1;
    dp.assign(n, vector<vector<long long>>(k, {0, 0}));
    g.assign(n,{});
    for (int i = 0; i < m; ++i) {
        int a,b;
        cin >> a >> b;
        a--;b--;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    dfs(0, -1);
    cout <<res;
}
/* Sat Jul 25 2020 12:55:12 GMT+0300 (Москва, стандартное время) */


#include<iostream>
#include<vector>
#include<stack>
#include<cmath>
#include<algorithm>
#include<set>
#include<map>
#include<string>
#include<tuple>
#include<bitset>
#include<queue>
#include<random>
#define double long double
//#define int long long
using namespace std;
long long gcd(long long i, long long j) {
    if (j == 0)return i;
    else return gcd(j, i % j);
}
template<typename T> inline T getint() {
    T val = 0;
    char c;

    bool neg = false;
    while ((c = getchar()) && !(c >= '0' && c <= '9')) {
        neg |= c == '-';
    }

    do {
        val = (val * 10) + c - '0';
    } while ((c = getchar()) && (c >= '0' && c <= '9'));

    return val * (neg ? -1 : 1);
}
const long long INF = 8e17;
const long long m = 1000000007;
const int Y = 200100;
int n, k;
long long ans = 0;
long long dp[5][Y];
long long dep[Y];
long long ct[Y];
vector<int>Ed[Y];
void dfs(int i, int p, int deep) {
    dp[deep % k][i] = 1;
    dep[i] = 1;
    for (auto x : Ed[i]) {
        if (x == p)continue;
        dfs(x, i, deep + 1);
        ans += dep[i] * (ct[x]  + dp[deep % k][x]);
        ans += ct[i] * dep[x];
        dep[i] += dep[x];
        ct[i] += ct[x] + dp[deep % k][x];
        //ans += ct[x];
        for (int j = 0; j < k; ++j) {
            for (int j1 = 0; j1 < k; ++j1) {
                int tmp = (j - deep % k + k) % k + (j1 - deep % k + k) % k;
                if (tmp > k) {
                    ans += 2 * dp[j][i] * dp[j1][x];
                }
                else if (tmp > 0)ans += dp[j][i] * dp[j1][x];
            }
        }
        for (int j = 0; j < k; ++j) {
            dp[j][i] += dp[j][x];
            //ans += dp[j][x];
        }
    }
   // ans += ct[i];
    //cout << i << " " << ans << "\n";
}
int32_t main()
{
    cin.tie(0);
    cout.tie(0);
    ios_base::sync_with_stdio(false);
    cout.precision(15);
    cin >> n >> k;
    for (int i = 0; i < n - 1; ++i) {
        int a, b;
        cin >> a >> b;
        Ed[a].push_back(b);
        Ed[b].push_back(a);
    }
    dfs(1, 0, 0);
    cout << ans;
	return 0;
}
/*
8 8
7 8 1 1
1 2 1 -1
2 3 1 -1
3 4 1 -1
4 1 1 -1
2 5 1 -10
5 6 1 -10
6 2 1 -10
7 8
*/
/* Fri Jul 10 2020 08:35:42 GMT+0300 (Москва, стандартное время) */

/* Sat Jul 11 2020 18:41:06 GMT+0300 (Москва, стандартное время) */

/* Sat Jul 11 2020 19:52:11 GMT+0300 (Москва, стандартное время) */
/* Thu Jul 23 2020 19:01:34 GMT+0300 (Москва, стандартное время) */


/// meowa

#pragma GCC optimize("O3")
//#pragma comment(linker, "/STACK:36777216")

#include<bits/stdc++.h>

#define x first
#define y second
#define pb push_back
#define sz(x) (int) x.size()

using namespace std;

using ll = long long;
using pii = pair<int, int>;

const int MOD = 1e9 + 7;
const int INF = 1e9 + 1e2;

void stndrtn() {
#ifdef AM
    freopen(".in", "r", stdin);
#endif
}

const bool flag = 0;

const int N = 1e5+10;

int n, k;

vector<int> adj[N];

ll ans = 0;

int sz[N], cnt[N][5];

int sub(int a, int b) {
    return (a-b+k) % k;
}

void dfs(int x = 0, int p = -1, int d = 0) {
    cnt[x][d%k] = sz[x] = 1;
    for (int to : adj[x]) {
        if (to != p) {
            dfs(to, x, d+1);
            for (int i = 0; i < k; ++i) {
                for (int j = 0; j < k; ++j) {
                    ans += sub(k, sub(i+j, d+d)) * 1ll * cnt[x][i] * cnt[to][j];
                }
            }
            for (int i = 0; i < k; ++i) {
                cnt[x][i] += cnt[to][i];
            }
            sz[x] += sz[to];
        }
    }
    ans += sz[x] * 1ll * (n-sz[x]);
}

void ma1n() {
    cin >> n >> k;
    for (int i = 1; i < n; ++i) {
        int u, v;
        cin >> u >> v;
        u--, v--;
        adj[u].pb(v);
        adj[v].pb(u);
    }
    dfs();
    cout << ans/k;
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(nullptr), stndrtn();
    int ts = 1;
    if (flag) {
        cin >> ts;
    }
    while (ts--) {
        ma1n();
    }
    return 0;
}
/* Sat Jul 25 2020 13:16:57 GMT+0300 (Москва, стандартное время) */


/// meowa

#pragma GCC optimize("O3")
//#pragma comment(linker, "/STACK:36777216")

#include<bits/stdc++.h>

#define x first
#define y second
#define pb push_back
#define sz(x) (int) x.size()

using namespace std;

using ll = long long;
using pii = pair<int, int>;

const int MOD = 1e9 + 7;
const int INF = 1e9 + 1e2;

void stndrtn() {
#ifdef AM
    freopen(".in", "r", stdin);
#endif
}

const bool flag = 0;

const int N = 2e5+10;

int n, k;

vector<int> adj[N];

ll ans = 0;

int sz[N], cnt[N][5];

int sub(int a, int b) {
    return (a-b+k) % k;
}

void dfs(int x = 0, int p = -1, int d = 0) {
    cnt[x][d%k] = sz[x] = 1;
    for (int to : adj[x]) {
        if (to != p) {
            dfs(to, x, d+1);
            for (int i = 0; i < k; ++i) {
                for (int j = 0; j < k; ++j) {
                    ans += sub(k, sub(i+j, d+d)) * 1ll * cnt[x][i] * cnt[to][j];
                }
            }
            for (int i = 0; i < k; ++i) {
                cnt[x][i] += cnt[to][i];
            }
            sz[x] += sz[to];
        }
    }
    ans += sz[x] * 1ll * (n-sz[x]);
}

void ma1n() {
    cin >> n >> k;
    for (int i = 1; i < n; ++i) {
        int u, v;
        cin >> u >> v;
        u--, v--;
        adj[u].pb(v);
        adj[v].pb(u);
    }
    dfs();
    cout << ans/k;
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(nullptr), stndrtn();
    int ts = 1;
    if (flag) {
        cin >> ts;
    }
    while (ts--) {
        ma1n();
    }
    return 0;
}
/* Sat Jul 25 2020 13:17:28 GMT+0300 (Москва, стандартное время) */


#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define x first
#define y second
#define pb push_back
#define mp make_pair
#define all(v) v.begin(),v.end()
#define sz(v) (int)v.size()
#define up_b upper_bound
#define low_b lower_bound
#define nl '\n'

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;

typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;

const int N=2e5+11;
const int M=2e6+11;
const int W=1e3+11;
const int inf=1e9;
const ll INF=1e18;
const ll mod=1e9+7;
const ld EPS=1e-9;

void add(int &a,int b){
  a+=b;
  if(a>=mod)a-=mod;
}

int mult(int a,int b){
  ll c=1ll*a*b;
  return c%mod;
}

vector<int>g[N];
int n,k,sz[N];
ll ans,res[6],cnt[6];

void dfs_sz(int v,int p){
  sz[v]=1;
  for(int i=0;i<sz(g[v]);i++){
    int to=g[v][i];
    if(to!=p){
      dfs_sz(to,v);
      sz[v]+=sz[to];
    }
  }
}

int find(int v,int p,int s){
  for(int i=0;i<sz(g[v]);i++){
    int to=g[v][i];
    if(to!=p){
      if(sz[to]>s/2){
        return find(to,v,s);
      }
    }
  }
  return v;
}

void calc(int v,int p,int h){
  int r=(h+k-1)/k;
  for(int i=1;i<=k;i++){
    if(i+(h-1)%k+1<=k)ans+=res[i]+1ll*(r-1)*cnt[i];
    else ans+=res[i]+1ll*r*cnt[i];
  }
  for(int i=0;i<sz(g[v]);i++){
    int to=g[v][i];
    if(to!=p){
      calc(to,v,h+1);
    }
  }
}

void upd(int v,int p,int h){
  int r=(h+k-1)/k;
  res[(h-1)%k+1]+=r;
  cnt[(h-1)%k+1]++;
  for(int i=0;i<sz(g[v]);i++){
    int to=g[v][i];
    if(to!=p){
      upd(to,v,h+1);
    }
  }
}

void dfs(int v){
  dfs_sz(v,v);
  int cen=find(v,v,sz[v]);
  for(int i=1;i<=k;i++){
    res[i]=0;
    cnt[i]=0;
  }
  cnt[k]++;
  for(int i=0;i<sz(g[cen]);i++){
    int to=g[cen][i];
    calc(to,cen,1);
    upd(to,cen,1);
    int pos=-1;
    for(int j=0;j<sz(g[to]);j++){
      if(g[to][j]==cen){
        pos=j;
        break;
      }
    }
    while(pos<sz(g[to])-1){
      swap(g[to][pos],g[to][pos+1]);
      pos++;
    }
    g[to].pop_back();
  }
  for(int i=0;i<sz(g[cen]);i++){
    int to=g[cen][i];
    dfs(to);
  }
}

int main(){
  ios_base::sync_with_stdio(0);
  cin.tie(0),cout.tie(0);
  cin>>n>>k;
  for(int i=1;i<n;i++){
    int u,v;
    cin>>u>>v;
    g[u].pb(v);
    g[v].pb(u);
  }
  dfs(1);
  cout<<ans;
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long int
#define ld long double
#define pb push_back
#define pll pair<ll, ll>
#define tri pair<pll, ll>
#define vl vector<ll>
#define vvl vector< vector<ll> >
#define vlp vector< pair<ll, ll> >
#define vllp vector<pair<pll, ll> >
#define mll map<ll, ll>
#define rep(i,a)  for(ll i=0; i< a; i++)
#define rep1(i,a)   for(ll i = 1; i< a; i++)
#define foi(i, a, b)    for(ll i = a; i<b ; i++)
#define fod(i, a, b)    for(ll i = a; i>=b ; i--)
#define mp make_pair
#define all(v)  (v).begin(), (v).end()
#define fst first
#define sec second
#define ff first.first
#define fs first.second
#define max3(a, b, c)   max(max(a, b), c)
#define min3(a, b, c)   min(min(a, b), c)
#define MAX 1000005
#define MOD 1000000007
// #define MOD 998244353
#define endl "\n"
#define INF (ll)1e18
#define s(v) (ll)v.size()
#define e(v) v.empty()
#define bscount(x) __builtin_popcountll(x)
// #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>

using namespace std;
// using namespace __gnu_pbds;

void __print(ll x) {cerr << x;}
void __print(ld x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

ll gcd(ll a, ll b){if(b==0)return a;return gcd(b, a%b);}
ll cpow(ll a, ll b, ll M){ll ans = 1;while(b){if(b&1) ans = ans*a%M; b/=2;a=a*a%M;}return ans;}
void ingraph(vvl& graph, ll m){ll x, y;rep(i, m){cin>>x>>y;x--, y--;graph[x].pb(y);graph[y].pb(x);}}
ll modify(ll n){ll res = n;res%=MOD;res+=MOD;res%=MOD;return res;}
ll fexp(ll a, ll b) {return cpow(a, b, MOD);}
ll cinv(ll a, ll p){return cpow(a, p-2, p);}
ll inverse(ll a)    {return cinv(a, MOD);}

ll n,k;
vl dsum(MAX), sub(MAX);
ll mod[MAX][5];
ll ans = 0;

void dfs(vvl& graph, ll v, ll par){
	sub[v]++;
	mod[v][0]++;
	for(ll u : graph[v]){
		if(u != par){
			dfs(graph, u, v);
			sub[v] += sub[u];
			rep(i, k){
				mod[v][i] += mod[u][(i-1+k)%k];
			}
			dsum[v] += dsum[u];
		}
	}
	dsum[v] += (sub[v]-1);
}

void reroot(vvl& graph, ll v, ll par){
	if(par != -1){
		vl temp(k);
		dsum[v] = dsum[par] + n - 2*sub[v];
		rep(i, k){
			temp[i] += (mod[par][(i-1+k)%k] - mod[v][(i-2+k)%k]);
		}
		rep(i, k)	mod[v][i] += temp[i];
	}
	ll tmp = dsum[v];
	rep(i, k){
		if(i > 0) tmp += mod[v][i]*(k-i);
	}
	ans += tmp/k;
	for(ll u : graph[v])
		if(u - par)
			reroot(graph, u, v);
}

int main(){
	#ifndef ONLINE_JUDGE
        freopen("../input.txt", "r", stdin);
        freopen("../output.txt", "w", stdout);
    #endif
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    ll t;
    // cin>>t;
    t = 1;
    ll tc = 0;
    while(tc++ < t){
        cin>>n>>k;
        vvl graph(n);
        ingraph(graph, n-1);
        dfs(graph, 0, -1);
        reroot(graph, 0, -1);
        cout<<ans/2;
    }
}


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
using namespace std;
const int maxn=200010;
int n,k,topt,st[maxn<<1],nt[maxn<<1],to[maxn<<1];
long long dp[maxn][5],si[maxn],ans;
bool f[maxn];
void add(int x,int y)
{to[++topt]=y; nt[topt]=st[x]; st[x]=topt;}
void dfs(int x,int de)
{
	f[x]=1; int p=st[x]; si[x]=1; dp[x][de%k]=1;
	while (p)
	{
		if (!f[to[p]])
		{
			dfs(to[p],de+1);
			for (int i=0;i<k;i++)
			 for (int j=0;j<k;j++)
			 {
			 	int d=(i+j-2*de%k+k)%k;
			 	int now=(k-d+k)%k;
			 	ans+=now*dp[x][i]*dp[to[p]][j];
			 }
			ans+=si[to[p]]*(n-si[to[p]]);
			for (int i=0;i<k;i++) dp[x][i]+=dp[to[p]][i];
			si[x]+=si[to[p]];
		}
		p=nt[p];
	}
}
int main()
{
	scanf("%d%d",&n,&k);
	for (int i=1;i<n;i++)
	{
		int x,y; scanf("%d%d",&x,&y);
		add(x,y); add(y,x);
	}
	dfs(1,0); printf("%lld\n",ans/k);
return 0;
}


#include <bits/stdc++.h>
using namespace std;

using ll = long long;

ll dp_sum[5][200001];
ll dp_no[5][200001];
bool vis[200001];
vector<int> adj[200001];

int k;
ll ans=0LL;
ll ans2=0LL;

void dfs(int v, int par)
{
	vis[v]=1;
	// dp_no[0][v]++;

	for(auto u:adj[v])
	{
		if(u!=par)
		{
			// a child

			dfs(u,v);

			for(int i=1; i<=k; i++)
			{
				dp_sum[i%k][v] += dp_no[i-1][u]+dp_sum[i-1][u];
				dp_no[i%k][v] += dp_no[i-1][u];
			}
		}
	}

	// count the number of paths that have a curve

	// dp_no[0][v]++;

	// cout << v << "!" << endl;

	for(auto u:adj[v])
	{
		if(u==par) continue; // just deal with children

		for(int i=0; i<k; i++)
		{
			for(int j=0; j<k; j++)
			{
				ll no_paths = dp_no[(i+k-1)%k][u] * (dp_no[j][v] - dp_no[(j+k-1)%k][u]);

				ans += (dp_sum[(i+k-1)%k][u]+dp_no[(i+k-1)%k][u]) * (dp_no[j][v] - dp_no[(j+k-1)%k][u]);
				ans += (dp_sum[j][v] - dp_sum[(j+k-1)%k][u] - dp_no[(j+k-1)%k][u])*dp_no[(i+k-1)%k][u]; // dp_no[][u] accounts for the extra path down
				ans += ((k+k-i-j)%k)*no_paths; // the rounding up of paths

				// if(u==3&&i==1&&j==0)
				// {
				// 	cout << "!!! " << dp_sum[(i+k-1)%k][u] << " " << no_paths << " " << dp_no[j][v] << " " << dp_no[(j+k-1)%k][u] << " " << dp_sum[j][v] << " " << dp_sum[(j+k-1)%k][u] << " " << dp_no[(j+k-1)%k][u] << " " << dp_no[(i+k-1)%k][u] << " " << ((k+k-i-j)%k) << " " << no_paths << endl;
				// }

				// cout << u << " " << i << " " << j << " " << no_paths << " " << ans << endl;
			}
		}
	}

	// now deal with the straight down paths

	for(int i=0; i<k; i++)
	{
		ans2+=dp_sum[i][v] + ((k-i)%k)*dp_no[i][v];
	}

	dp_no[0][v]++;
}

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);

	#ifdef ARTHUR_LOCAL
		ifstream cin("input.txt");
	#endif

	int n;
	cin>>n>>k;

	for(int i=0; i<n-1; i++)
	{
		int a,b;
		cin>>a>>b;
		adj[a].push_back(b);
		adj[b].push_back(a);
	}

	dfs(1,-1);

	// for(int i=1; i<=n; i++)
	// {
	// 	cout << i << " " << dp_no[0][i] << " " << dp_sum[0][i] << endl;
	// 	cout << "  " << dp_no[1][i] << " " << dp_sum[1][i] << endl << endl;

	// }

	cout << ll(ans/ll(k+k)) + ll(ans2/ll(k)) << endl;

	// cout << ans2 << endl;
}


#include<bits/stdc++.h>
using namespace std;
#define maxn 200005
typedef long long ll;
ll siz[maxn],siz2[maxn][5];//x的子树里到根节点距离mod k=y的点的个数
vector<int>g[maxn];
int n,k;
ll ans=0;
int sub(int x,int y)
{
	return ((x-y)%k+k)%k;
}
void dfs(int x,int fa,int dep)
{
//	cout<<x<<endl;
	siz[x]=siz2[x][dep%k]=1;
	for(int i=0;i<g[x].size();i++)
	{
		int y=g[x][i];
		if(y==fa)continue;
		dfs(y,x,dep+1);
		for(int a=0;a<k;a++)
			for(int b=0;b<k;b++)
			{
				int dist=sub(a+b,2*dep);
				int need=sub(k,dist);
				ans+=(ll)need*siz2[x][a]*siz2[y][b];
			}
		for(int i=0;i<k;i++)
			siz2[x][i]+=siz2[y][i];
		siz[x]+=siz[y];
	}
	ans+=siz[x]*(ll)(n-siz[x]);
}
int main()
{
	scanf("%d%d",&n,&k);
	for(int i=1;i<n;i++)
	{
		int u,v;
		scanf("%d%d",&u,&v);
		g[u].push_back(v);
		g[v].push_back(u);
	}
	dfs(1,-1,0);
	printf("%lld\n",ans/k);
    return 0;
}
/*
4 4 6
2 1
2 2
2 3
4 2
4 3
4 4

4 4 5
1 4
2 4
3 2
3 4
4 4
*/


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 2e5 + 1;
const int K = 5;
int cnt[N][K];
int sum[N][K];
int n, k;
ll ans;

bool vis[N];
vector <int> adj[N];

void input() {
    cin >> n >> k;
    for(int i = 1; i < n; ++i) {
        int u; cin >> u;
        int v; cin >> v;
        adj[u].push_back(v);
        adj[v].push_back(u);
    }
}

void dfs(int u) {
    vis[u] = 1;
    cnt[u][0] = 1;
    sum[u][0] = 0;
    for(int v: adj[u]) {
        if(!vis[v]) {
            dfs(v);
            int tmp_cnt[k];
            int tmp_sum[k];
            for(int i = 0; i < k; ++i) {
                tmp_cnt[(i + 1) % k] = cnt[v][i];
                tmp_sum[(i + 1) % k] = sum[v][i];
            }
            tmp_sum[1 % k] += tmp_cnt[1 % k];
            for(int i = 0; i < k; ++i) {
                for(int j = 0; j < k; ++j) {
                    if(k - (i? i: k) + k - (j? j: k) < k) {
                        ans += 1ll * cnt[u][i] * tmp_sum[j] +
                               1ll * sum[u][i] * tmp_cnt[j];
                    }
                    else {
                        ans += 1ll * cnt[u][i] * tmp_sum[j] +
                               1ll * sum[u][i] * tmp_cnt[j] -
                               1ll * cnt[u][i] * tmp_cnt[j];
                    }
                }
            }
            for(int i = 0; i < k; ++i) {
                cnt[u][i] += tmp_cnt[i];
                sum[u][i] += tmp_sum[i];
            }
        }
    }
}

void solve() {
    dfs(1);
    cout << ans << "\n";
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    input();
    solve();
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 2e5 + 1;
const int K = 5;
int n, k;

ll cnt[N][K];
ll sum[N][K];
ll ans;

bool vis[N];
vector <int> adj[N];

void input() {
    cin >> n >> k;
    for(int i = 1; i < n; ++i) {
        int u; cin >> u;
        int v; cin >> v;
        adj[u].push_back(v);
        adj[v].push_back(u);
    }
}

void dfs(int u) {
    vis[u] = 1;
    cnt[u][0] = 1;
    sum[u][0] = 0;
    for(int v: adj[u]) {
        if(!vis[v]) {
            dfs(v);
            int tmp_cnt[k];
            int tmp_sum[k];
            for(int i = 0; i < k; ++i) {
                tmp_cnt[(i + 1) % k] = cnt[v][i];
                tmp_sum[(i + 1) % k] = sum[v][i];
            }
            tmp_sum[1 % k] += tmp_cnt[1 % k];
            for(int i = 0; i < k; ++i) {
                for(int j = 0; j < k; ++j) {
                    if(k - (i? i: k) + k - (j? j: k) < k) {
                        ans += 1ll * cnt[u][i] * tmp_sum[j] +
                               1ll * sum[u][i] * tmp_cnt[j];
                    }
                    else {
                        ans += 1ll * cnt[u][i] * tmp_sum[j] +
                               1ll * sum[u][i] * tmp_cnt[j] -
                               1ll * cnt[u][i] * tmp_cnt[j];
                    }
                }
            }
            for(int i = 0; i < k; ++i) {
                cnt[u][i] += tmp_cnt[i];
                sum[u][i] += tmp_sum[i];
            }
        }
    }
}

void solve() {
    dfs(1);
    cout << ans << "\n";
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    input();
    solve();
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 2e5 + 1;
const int K = 5;
int n, k;

ll cnt[N][K];
ll sum[N][K];
ll ans;

bool vis[N];
vector <int> adj[N];

void input() {
    cin >> n >> k;
    for(int i = 1; i < n; ++i) {
        int u; cin >> u;
        int v; cin >> v;
        adj[u].push_back(v);
        adj[v].push_back(u);
    }
}

void dfs(int u) {
    vis[u] = 1;
    cnt[u][0] = 1;
    sum[u][0] = 0;
    for(int v: adj[u]) {
        if(!vis[v]) {
            dfs(v);
            ll tmp_cnt[k];
            ll tmp_sum[k];
            for(int i = 0; i < k; ++i) {
                tmp_cnt[(i + 1) % k] = cnt[v][i];
                tmp_sum[(i + 1) % k] = sum[v][i];
            }
            tmp_sum[1 % k] += tmp_cnt[1 % k];
            for(int i = 0; i < k; ++i) {
                for(int j = 0; j < k; ++j) {
                    if(k - (i? i: k) + k - (j? j: k) < k) {
                        ans += cnt[u][i] * tmp_sum[j] +
                               sum[u][i] * tmp_cnt[j];
                    }
                    else {
                        ans += cnt[u][i] * tmp_sum[j] +
                               sum[u][i] * tmp_cnt[j] -
                               cnt[u][i] * tmp_cnt[j];
                    }
                }
            }
            for(int i = 0; i < k; ++i) {
                cnt[u][i] += tmp_cnt[i];
                sum[u][i] += tmp_sum[i];
            }
        }
    }
}

void solve() {
    dfs(1);
    cout << ans << "\n";
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    input();
    solve();
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 2e5 + 1;
const int K = 5;
int cnt[N][K];
int sum[N][K];
int n, k;
ll ans;

bool vis[N];
vector <int> adj[N];

void input() {
    cin >> n >> k;
    for(int i = 1; i < n; ++i) {
        int u; cin >> u;
        int v; cin >> v;
        adj[u].push_back(v);
        adj[v].push_back(u);
    }
}

void dfs(int u) {
    vis[u] = 1;
    cnt[u][0] = 1;
    sum[u][0] = 0;
    for(int v: adj[u]) {
        if(!vis[v]) {
            dfs(v);
            int tmp_cnt[k];
            int tmp_sum[k];
            for(int i = 0; i < k; ++i) {
                tmp_cnt[(i + 1) % k] = cnt[v][i];
                tmp_sum[(i + 1) % k] = sum[v][i];
            }
            tmp_sum[1] += tmp_cnt[1];
            for(int i = 0; i < k; ++i) {
                for(int j = 0; j < k; ++j) {
                    if(k - (i? i: k) + k - (j? j: k) < k) {
                        ans += 1ll * cnt[u][i] * tmp_sum[j] +
                               1ll * sum[u][i] * tmp_cnt[j];
                    }
                    else {
                        ans += 1ll * cnt[u][i] * tmp_sum[j] +
                               1ll * sum[u][i] * tmp_cnt[j] -
                               1ll * cnt[u][i] * tmp_cnt[j];
                    }
                }
            }
            for(int i = 0; i < k; ++i) {
                cnt[u][i] += tmp_cnt[i];
                sum[u][i] += tmp_sum[i];
            }
        }
    }
}

void solve() {
    dfs(1);
    cout << ans << "\n";
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    input();
    solve();
}


#include <bits/stdc++.h>

using namespace std;

#define loop(i, n) for(int i = 0;i < int(n);i++)
#define rloop(i, n) for(int i = int(n);i >= 0;i--)
#define range(i, a, b) for(int i = int(a);i <= int(b);i++)
#define SZ(c) int(c.size())
#define ALL(c) c.begin(), c.end()
#define RALL(c) c.rbegin(), c.rend()
#define PI acos(-1)
#define pb push_back
#define mp make_pair
#define fr first
#define sc second
#define sfi1(v) scanf("%d",&v)
#define sfi2(v1, v2) scanf("%d %d",&v1,&v2)
#define sfi3(v1, v2, v3) scanf("%d %d %d",&v1,&v2,&v3)
#define sfll1(v) scanf("%I64d",&v);
#define sfll2(v1, v2) scanf("%I64d %I64d",&v1,&v2)
#define sfll3(v1, v2, v3) scanf("%I64d %I64d %I64d",&v1,&v2,&v3)
#define endl '\n'

typedef vector<int> vi;
typedef vector<pair<int, int> > vii;
typedef long long ll;
typedef pair<int, int> pii;

const int N = 2e5 + 5;
const int K = 7;
vi adj[N];
int sub[N][K], sz[N];
int n, k;
ll ans = 0;

void dfs(int u, int par) {
    sz[u]++;
    sub[u][0]++;

    for (int nxt : adj[u]) {
        if (nxt == par)continue;
        dfs(nxt, u);
        loop(i, k) {
            loop(j, k) {
                int rem = (i + j) % k;
                int need = rem ? k - rem : 0;
                ans += 1LL * sub[u][i] * sub[nxt][(j - 1 + k) % k] * need;
            }
        }
        loop(i, k)sub[u][(i + 1) % k] += sub[nxt][i];
        sz[u] += sz[nxt];
    }
    ans += 1LL * sz[u] * (n - sz[u]);
}

int main() {

#ifndef ONLINE_JUDGE
    //freopen("in.in", "r", stdin);
    //freopen("out.in", "w", stdout);
#endif
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    int a, b;
    cin >> n >> k;
    loop(i, n - 1) {
        cin >> a >> b;
        adj[a].pb(b);
        adj[b].pb(a);
    }

    dfs(1, -1);
    cout << ans / k << endl;

    return 0;
}


///------------------  CODE FOR FUN -------------------
#include <bits/stdc++.h>
#define FOR(i,j,k) for(int i = j; i <= k; i ++)
#define FORD(i,j,k) for(int i = j; i >= k; i --)
#define mp make_pair
//#define f first
//#define s second
//#define int long long
using namespace std;

const int MOD=1e9+7;
const int N = 200005;
int n, k;
vector < int > ke[N];
int F[N][10], S[N];
long long res = 0;
void DFS(int u, int p)
{
    F[u][0] = 1;
    for(int v : ke[u])
    {
        if(v == p) continue;
        DFS(v, u);
        FOR(i, 1, k - 1) F[u][i] += F[v][i - 1];
        F[u][0] += F[v][k - 1];
        S[u] += S[v] + F[v][0];
    }
}
void DFS2(int u, int p)
{
//    cout << u << " " << S[u] << "\n";
    res += S[u];
    for(int v : ke[u])
    {
        if(v == p) continue;
        FOR(i, 1, k - 1) F[u][i] -= F[v][i - 1];
        F[u][0] -= F[v][k - 1];
        S[u] -= S[v] + F[v][0];
        FOR(i, 1, k - 1) F[v][i] += F[u][i - 1];
        F[v][0] += F[u][k - 1];
        S[v] += S[u] + F[u][0];
        DFS2(v, u);
        FOR(i, 1, k - 1) F[v][i] -= F[u][i - 1];
        F[v][0] -= F[u][k - 1];
        S[v] -= S[u] + F[u][0];
        FOR(i, 1, k - 1) F[u][i] += F[v][i - 1];
        F[u][0] += F[v][k - 1];
        S[u] += S[v] + F[v][0];
    }
}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    //#define task"C"
    //freopen(task".inp","r",stdin);
    //freopen(task".out","w",stdout);
    cin >> n >> k;
    FOR(i, 1, n - 1)
    {
        int u, v;
        cin >> u >> v;
        ke[u].push_back(v);
        ke[v].push_back(u);
    }
    DFS(1, -1);
    DFS2(1, -1);
    cout << res/2;
    return 0;
}


///------------------  CODE FOR FUN -------------------
#include <bits/stdc++.h>
#define FOR(i,j,k) for(int i = j; i <= k; i ++)
#define FORD(i,j,k) for(int i = j; i >= k; i --)
#define mp make_pair
//#define f first
//#define s second
//#define int long long
using namespace std;

const int MOD=1e9+7;
const int N = 200005;
int n, k;
vector < int > ke[N];
int F[N][10], S[N];
long long res = 0;
void DFS(int u, int p)
{
    F[u][0] = 1;
    for(int v : ke[u])
    {
        if(v == p) continue;
        DFS(v, u);
        FOR(i, 1, k - 1) F[u][i] += F[v][i - 1];
        F[u][0] += F[v][k - 1];
        S[u] += S[v] + F[v][0];
    }
}
void DFS2(int u, int p)
{
//    cout << u << " " << S[u] << "\n";
    res += S[u];
    for(int v : ke[u])
    {
        if(v == p) continue;
        FOR(i, 1, k - 1) F[u][i] -= F[v][i - 1];
        F[u][0] -= F[v][k - 1];
        S[u] -= S[v] + F[v][0];
        FOR(i, 1, k - 1) F[v][i] += F[u][i - 1];
        F[v][0] += F[u][k - 1];
        S[v] += S[u] + F[u][0];
        DFS2(v, u);
        FOR(i, 1, k - 1) F[v][i] -= F[u][i - 1];
        F[v][0] -= F[u][k - 1];
        S[v] -= S[u] + F[u][0];
        FOR(i, 1, k - 1) F[u][i] += F[v][i - 1];
        F[u][0] += F[v][k - 1];
        S[u] += S[v] + F[v][0];
    }
}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    #define task"C"
    freopen(task".inp","r",stdin);
    freopen(task".out","w",stdout);
    cin >> n >> k;
    FOR(i, 1, n - 1)
    {
        int u, v;
        cin >> u >> v;
        ke[u].push_back(v);
        ke[v].push_back(u);
    }
    DFS(1, -1);
    DFS2(1, -1);
    cout << res/2;
    return 0;
}


///------------------  CODE FOR FUN -------------------
#include <bits/stdc++.h>
#define FOR(i,j,k) for(int i = j; i <= k; i ++)
#define FORD(i,j,k) for(int i = j; i >= k; i --)
#define mp make_pair
//#define f first
//#define s second
//#define int long long
using namespace std;

const int MOD=1e9+7;
const int N = 200005;
int n, k;
vector < int > ke[N];
int F[N][10];
long long res = 0, S[N];
void DFS(int u, int p)
{
    F[u][0] = 1;
    for(int v : ke[u])
    {
        if(v == p) continue;
        DFS(v, u);
        FOR(i, 1, k - 1) F[u][i] += F[v][i - 1];
        F[u][0] += F[v][k - 1];
        S[u] += S[v] + F[v][0];
    }
}
void DFS2(int u, int p)
{
//    cout << u << " " << S[u] << "\n";
    res += S[u];
    for(int v : ke[u])
    {
        if(v == p) continue;
        FOR(i, 1, k - 1) F[u][i] -= F[v][i - 1];
        F[u][0] -= F[v][k - 1];
        S[u] -= S[v] + F[v][0];
        FOR(i, 1, k - 1) F[v][i] += F[u][i - 1];
        F[v][0] += F[u][k - 1];
        S[v] += S[u] + F[u][0];
        DFS2(v, u);
        FOR(i, 1, k - 1) F[v][i] -= F[u][i - 1];
        F[v][0] -= F[u][k - 1];
        S[v] -= S[u] + F[u][0];
        FOR(i, 1, k - 1) F[u][i] += F[v][i - 1];
        F[u][0] += F[v][k - 1];
        S[u] += S[v] + F[v][0];
    }
}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
   // #define task"C"
   // freopen(task".inp","r",stdin);
   // freopen(task".out","w",stdout);
    cin >> n >> k;
    FOR(i, 1, n - 1)
    {
        int u, v;
        cin >> u >> v;
        ke[u].push_back(v);
        ke[v].push_back(u);
    }
    DFS(1, -1);
    DFS2(1, -1);
    cout << res/2;
    return 0;
}


#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// #define ordered_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>

#define ll long long
#define int long long
#define FOR(i, x, y) for(int i = x; i <= y; ++i)
#define pb push_back
#define eb emplace_back
#define Size(v) (int)v.size()

using namespace std;
// using namespace __gnu_pbds;

const int nax = 2e5 + 5;
int sz[nax], dep[nax], dp[nax][6];
int n, k, all = 0;
vector<vector<int>> adj;
vector<pair<int, int>> edge;
int res = 0;

int add(int i, int j) {
	return ((i + j + k) % k + k) % k;
}

int distance(int i, int j) {
	return ((j - i) % j + j) % j;
}

void dfs(int v, int p = 0) {
	sz[v] = 1;
	if (p != 0) dep[v] = dep[p] + 1;

	for (auto &c : adj[v]) {
		if (c == p) continue;

		dfs(c, v);

		sz[v] += sz[c];
	}

	all += (sz[v] * (n - sz[v]));
}

void dfs2(int v, int p = 0) {
	dp[v][0] = 1;

	for (auto &c : adj[v]) {
		if (c == p) continue;

		dfs2(c, v);

		for (int i = 0; i < k; ++i) {
			for (int j = 0; j < k; ++j) {
				int need = distance(i + j, k);
				res += need * dp[c][add(i, -1)] * dp[v][j];
			}
		}

		for (int i = 0; i < k; ++i) {
			dp[v][i] += dp[c][add(i, -1)];
		}
	}

	// for (int i = 0; i < k; ++i) {
	// 	int need = distance(i, k);
	// 	res += need * dp[v][i];
	// }
}

void solve() {
	cin >> n >> k;

	adj.resize(n + 1);

	FOR (i, 1, n - 1) {
		int u, v; cin >> u >> v;
		adj[u].pb(v);
		adj[v].pb(u);
		edge.pb({u, v});
	}

	dfs(1);

	// dp[i][j]: number of paths in subtree i having length of j modulo k

	// cerr << "all: " << all << '\n';

	dfs2(1);

	// cerr << distance(0, k);
	// cerr << distance(1, k);

	FOR (i, 1, n) {
		FOR (j, 0, k - 1) {
			// cerr << "i - j: " << i << ' ' << j << ' ' << dp[i][j] << '\n';
		}
	}

	all += res;

	cout << all / k;
}

signed main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);

	int t = 1;
	while (t--)
		solve();
	return 0;
}


#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// #define ordered_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>

#define ll long long
#define int long long
#define FOR(i, x, y) for(int i = x; i <= y; ++i)
#define pb push_back
#define eb emplace_back
#define Size(v) (int)v.size()

using namespace std;
// using namespace __gnu_pbds;

const int nax = 2e5 + 5;
int sz[nax], dep[nax], dp[nax][6];
int n, k, all = 0;
vector<vector<int>> adj;
vector<pair<int, int>> edge;
int res = 0;

int add(int i, int j) {
	return ((i + j + k) % k + k) % k;
}

int distance(int i, int j) {
	return ((j - i) % j + j) % j;
}

void dfs(int v, int p = 0) {
	sz[v] = 1;
	if (p != 0) dep[v] = dep[p] + 1;

	for (auto &c : adj[v]) {
		if (c == p) continue;

		dfs(c, v);

		sz[v] += sz[c];
	}

	all += (sz[v] * (n - sz[v]));
}

void dfs2(int v, int p = 0) {
	dp[v][0] = 1; // path length 0 from v

	for (auto &c : adj[v]) {
		if (c == p) continue;

		dfs2(c, v);

		// SImilar implementation idea to @766E
		for (int i = 0; i < k; ++i) {
			for (int j = 0; j < k; ++j) {
				int need = distance(i + j, k);
				res += need * dp[c][add(i, -1)] * dp[v][j];
			}
		}

		for (int i = 0; i < k; ++i) {
			dp[v][i] += dp[c][add(i, -1)];
		}
	}
}

void solve() {
	cin >> n >> k;

	adj.resize(n + 1);

	FOR (i, 1, n - 1) {
		int u, v; cin >> u >> v;
		adj[u].pb(v);
		adj[v].pb(u);
		edge.pb({u, v});
	}

	dfs(1);

	// dp[i][j]: number of paths in subtree i, from i, having length of j modulo k

	dfs2(1);

	all += res;

	cout << all / k;
}

signed main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);

	int t = 1;
	while (t--)
		solve();
	return 0;
}


//Utkarsh.25dec
#include <bits/stdc++.h>
#include <chrono>
#include <random>
#define ll long long int
#define ull unsigned long long int
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define rep(i,n) for(ll i=0;i<n;i++)
#define loop(i,a,b) for(ll i=a;i<=b;i++)
#define vi vector <int>
#define vs vector <string>
#define vc vector <char>
#define vl vector <ll>
#define all(c) (c).begin(),(c).end()
#define max3(a,b,c) max(max(a,b),c)
#define min3(a,b,c) min(min(a,b),c)
#define deb(x) cerr<<#x<<' '<<'='<<' '<<x<<'\n'
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
// ordered_set s ; s.order_of_key(val)  no. of elements strictly less than val
// s.find_by_order(i)  itertor to ith element (0 indexed)
typedef vector<vector<ll>> matrix;
ll power(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll modInverse(ll a){return power(a,mod-2);}
const int N=200023;
bool vis[N];
vector <int> adj[N];
ll endat[N][8],overall[N][8],cross[N][8];
ll subtree[N];
ll ans=0;
ll sum[8];
ll n,k;
void recurse(int curr,int par)
{
    subtree[curr]=1;
    for(int i:adj[curr])
    {
        if(i==par)
            continue;
        recurse(i,curr);
        subtree[curr]+=subtree[i];
    }
    endat[curr][0]=1;
    overall[curr][0]=1;
    for(int i=0;i<k;i++)
        sum[i]=0;
    for(int rem=0;rem<k;rem++)
    {
        for(int i:adj[curr])
        {
            if(i==par)
                continue;
            endat[curr][rem]+=endat[i][(rem+k-1)%k];
            overall[curr][rem]=endat[curr][rem];
            sum[rem]+=endat[i][rem];
        }
    }
    for(int i=0;i<k;i++)
    {
        for(int j=0;j<k;j++)
        {
            for(int child:adj[curr])
            {
                if(child==par)
                    continue;
                cross[curr][(i+j+2)%k]+=((sum[j]-endat[child][j])*(endat[child][i]));
            }
        }
    }
    for(int i=0;i<k;i++)
    {
        cross[curr][i]/=2;
        overall[curr][i]+=cross[curr][i];
    }
    for(int i:adj[curr])
    {
        if(i==par)
            continue;
        ans+=((n-subtree[i])*(subtree[i]));
    }
    for(int rem=0;rem<k;rem++)
    {
        ans+=(overall[curr][rem]*((k-rem)%k));
    }
}
void solve()
{
    cin>>n>>k;
    rep(i,n-1)
    {
        ll a,b;
        cin>>a>>b;
        adj[a].pb(b);
        adj[b].pb(a);
    }
    recurse(1,0);
    cout<<ans/k<<'\n';
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int T=1;
    //cin>>T;
    int t=0;
    while(t++<T)
    {
        //cout<<"Case #"<<t<<":"<<' ';
        solve();
        //cout<<'\n';
    }
    cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
}


#include <bits/stdc++.h>

using namespace std;

using ll = long long;

constexpr int kMaxN = 2e5 + 3;
constexpr int kMaxK = 5;

vector<int> edges[kMaxN];
int sz[kMaxN];
array<ll, kMaxK> counts[kMaxN];
ll total;
int n, k;

int dfs(int u, int p) {
  auto& cur = counts[u];
  cur[0] = 1;
  sz[u] = 1;
  for (int v: edges[u]) {
    if (v != p) {
      sz[u] += dfs(v, u);

      auto& ch = counts[v];
      for (int i = 0; i < k; ++i) {
        for (int j = 0; j < k; ++j) {
          int rem = (i + j + 1) % k;
          rem = (k - rem) % k;
          total += 1LL * cur[i] * ch[j] * rem;
        }
      }

      for (int i = 0; i < k; ++i) {
        cur[(i + 1) % k] += ch[i];
      }
    }
  }

  total += 1LL * sz[u] * (n - sz[u]);

  return sz[u];
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);

  cin >> n >> k;

  for (int i = 1; i < n; ++i) {
    int a, b;
    cin >> a >> b;
    --a, --b;

    edges[a].emplace_back(b);
    edges[b].emplace_back(a);
  }

  dfs(0, -1);

  assert(total % k == 0);

  cout << total / k << '\n';

  return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=4e5+10;
int h[N],ne[N],e[N],idx;
ll f[N][6];
ll g[N][6];
int n,k;
ll ans=0;
void add(int a,int b){
    e[idx]=b,ne[idx]=h[a],h[a]=idx++;
}
void dfs(int u,int fa){
    int i;
    f[u][k]=0,g[u][k]=1;
    for(i=h[u];i!=-1;i=ne[i]){
        int j=e[i];
        if(j==fa)
            continue;
        dfs(j,u);
        for(int x=1;x<=k;x++){
            if(x==1){
                f[u][x]+=f[j][k]+g[j][k];
                g[u][x]+=g[j][k];
            }
            else{
                f[u][x]+=f[j][x-1];
                g[u][x]+=g[j][x-1];
            }
        }
    }
}
void dfs1(int u,int fa){
	for (int i=1;i<=k;i++)
        ans=ans+1ll*f[u][i];
	for (int i=h[u];i!=-1;i=ne[i]){
		int x=e[i];
		if(x==fa)
            continue;
		ll tmpa[10],tmpb[10],tmpc[10],tmpd[10];
		for(int j=1;j<=k;j++) tmpa[j]=f[u][j];
		for(int j=1;j<=k;j++) tmpc[j]=g[u][j];
		for(int j=1;j<=k;j++)
			if(j==1)
                f[u][j]=f[u][j]-f[x][k]-g[x][k],g[u][j]=g[u][j]-g[x][k];
			else
                f[u][j]-=f[x][j-1],g[u][j]-=g[x][j-1];
		for(int j=1;j<=k;j++)
			if(j==1) f[x][j]+=f[u][k]+g[u][k],g[x][j]+=g[u][k];
			else f[x][j]+=f[u][j-1],g[x][j]+=g[u][j-1];
		dfs1(x,u);
        for (int j=1;j<=k;j++) f[u][j]=tmpa[j];
		for (int j=1;j<=k;j++) g[u][j]=tmpc[j];
	}
}
int main(){
    ios::sync_with_stdio(false);
    memset(h,-1,sizeof h);
    int i;
    cin>>n>>k;
    for(i=1;i<n;i++){
        int a,b;
        cin>>a>>b;
        add(a,b);
        add(b,a);
    }
    dfs(1,-1);
    dfs1(1,-1);
    cout<<ans/2<<endl;
	return 0;
}


/*And I thought my jokes were bad*/
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define dbg puts("Viva la vida");
#define CHECK(x) cout << (#x) << " is " << (x) << endl;
#define nl puts("");
#define mp make_pair
#define IN(x) scanf("%d",&x);
#define INL(x) scanf("%lld",&x);
#define OUT(x) printf("%d",x);
#define OUTL(x) printf("%lld",x);
#define MAX 200005
#define MOD 1000000007
#define INF (1 << 31)
#define CASE(x,y) printf("Case %d: %d\n",++x,y);
#define FASTIO ios::sync_with_stdio(false);cin.tie(0);
#define PI acos(-1.0)
#define EPS 1e-19
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define int ll
/*
	when i get older
	i will be stronger
	they'll call me freedom
	just like a waving flag
*/
int mat[MAX][5],dp[MAX];
vector<int> adj[MAX];
int k;
void dfs(int n=1,int par=0)
{
	for(auto &cv:adj[n])
	{
		if(cv==par)
			continue;
		dfs(cv,n);
		dp[n]+=dp[cv]+mat[cv][0];
		for(int i=0;i<k;i++)
		{

			mat[n][(i+1)%k]+=mat[cv][i];
		}
	}
	mat[n][0]++;

}
void dfs1(int n=1,int par=0)
{
	int pre=dp[n]+mat[n][0];
	pre=dp[par]-pre;
	// if(n==3)
	// 	CHECK(dp)

	if(par)
	dp[n]+=pre+mat[par][0]-mat[n][k-1];
	int ad[5];
	for(int i=0;i<k;i++)
	{
		if(par)
		{
			ad[(i+1)%k]=mat[par][i]-mat[n][(i-1+k)%k];
		}
	}
	for(int i=0;i<k;i++)
	{
		if(par)
		mat[n][i]+=ad[i];
	}
	for(auto &cv:adj[n])
	{
		if(cv==par)
			continue;
		dfs1(cv,n);
	}
}
void solve()
{
	int i,j,l,r,m,n,a,b,c,d,x,y,z,t;
	cin>>n>>k;
	for(i=1;i<n;i++)
	{
		cin>>x>>y;
		adj[x].push_back(y);
		adj[y].push_back(x);
	}
	dfs();

	dfs1();
	int ans=0;
	for(i=1;i<=n;i++)
		ans+=dp[i];
	cout<<ans/2<<endl;

}
int32_t main()
{
	FASTIO
    int t=1;
    // cin>>t;
    while(t--) solve();
    return 0;
}


//Author: Artem Romanov
#include <bits/stdc++.h>
//#define TASK "file"

#define F first
#define S second
#define ALL(x) (x).begin(), (x).end()

using namespace std;
typedef long double dbl;
const dbl PI = acos(-1.0L);
const dbl EPS = 1e-12L;
mt19937 rng((uint32_t) chrono::steady_clock::now().time_since_epoch().count());

namespace task {
const int N = 200000;
const int K = 5;
int n, k, a, b;
int64_t r;
vector<int> g[N];
int64_t d[N];
int m[N][K];
int64_t ud[N];
int um[N][K];

int mod(int v) {
  return (k + (v % k)) % k;
}

void dfs(int v = 0, int p = 0) {
  ++m[v][0];
  for (int c : g[v]) {
    if (c != p) {
      dfs(c, v);
      d[v] += d[c] + m[c][k - 1];
      for (int i = 0; i < k; ++i) {
        m[v][i] += m[c][mod(i - 1)];
      }
    }
  }
}

void sol(int v = 0, int p = 0) {
  r += d[v] + ud[v] + n - m[v][0] - um[v][0];
  for (int c : g[v]) {
    if (c != p) {
      ud[c] = ud[v] + d[v] - d[c] - m[c][k - 1];
      for (int i = 0; i < k; ++i) {
        um[c][i] += um[v][mod(i - 1)] + m[v][mod(i - 1)] - m[c][mod(i - 2)];
      }
      ud[c] += um[c][0];
      sol(c, v);
    }
  }
}

int main() {
  cin >> n >> k;
  for (int i = 1; i < n; ++i) {
    cin >> a >> b;
    --a;
    --b;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  dfs();
  sol();
  cout << r / 2 << '\n';
  return 0;
}
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.precision(11);
  cout.setf(ios::fixed);
#ifdef _DEBUG
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#elif defined(TASK)
  freopen(TASK".in", "r", stdin);
  freopen(TASK".out", "w", stdout);
#endif
  return task::main();
}

/* Sat Jan 26 2019 05:45:56 GMT+0300 (MSK) */


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int ui;

#pragma comment(linker, "/STACK:36777216")
//#pragma GCC optimize("O3")
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
#define double long double
#define ff first
#define ss second
#define int ll
#define fori(n) for (int i = 0; i < (n); i++)
#define forj(n) for (int j = 0; j < (n); j++)
#define endl "\n"

inline void boostIO() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cout.precision(10);
}
inline int safe_mul(int x, int y, int mod) {
	return x * 1LL * y % mod;
}

inline void safe_add(int& x, int y, int mod) {
	x += y;
	if (x >= mod)
		x -= mod;
}

const ll INF = 1e17;
const int modulo = 1e9 + 7;
const double EPS = 1e-7;
const double pi = 3.14159265358979323846;

int gcd(int a, int b)
{
	if (b == 0) return a;
	a %= b;
	return gcd(b, a);
}

int lcm(int a, int b) {
	return a * b / gcd(a, b);
}

int optpow(int a, int b, int k) {
	if (b == 0)
		return 1;
	int tmp = optpow(a, b / 2, k);
	if (b % 2 == 1) {
		return ((tmp*tmp) % k * a) % k;
	}
	else {
		return (tmp*tmp) % k;
	}
}

int qckpow(int a, int b) {
	if (b == 0)
		return 1;
	int tmp = qckpow(a, b / 2);
	if (b % 2 == 1) {
		return ((tmp*tmp) * a);
	}
	else {
		return (tmp*tmp);
	}
}

bool comp(pair<int, int> p1, pair<int, int> p2) {
	if (p1.ss == p2.ss)
		return p1.ff < p2.ff;
	return p1.ss < p2.ss;
}

const int maxn = 2e5 + 10;
vector<int> g[maxn];

int n, k;
int dp[maxn][5];
int dpth[maxn];
int temp[maxn][5];
int ans = 0;

void dfs1(int v, int p) {
	dp[v][0] = 1;
	for (auto to : g[v]) {
		if (to == p)
			continue;
		dpth[to] = dpth[v] + 1;
		dfs1(to, v);
		fori(k) {
			dp[v][(i + 1) % k] += dp[to][i];
		}
	}
}

void dfs2(int v, int p, int curans, int t[5]) {
	ans += curans;
	for (auto to : g[v]) {
		if (to == p)
			continue;
		fori(k) {
			temp[to][i] += dp[to][i];
			temp[to][(i + 1) % k] += t[i] - dp[to][(i - 1 + k) % k];
		}
		dfs2(to, v, curans - dp[to][0] + t[0] - dp[to][k - 1], temp[to]);
	}
}

int32_t main() {
	boostIO();
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	cin >> n >> k;
	fori(n - 1) {
		int u, v;
		cin >> u >> v;
		g[u].push_back(v);
		g[v].push_back(u);
	}
	dfs1(1, -1);
	int curans = 0;
	fori(n) {
		int te = dpth[i + 1];
		curans += (te + te % k) / k;
	}
	dfs2(1, -1, curans, dp[1]);
	cout << ans / 2;
}

/* Mon Mar 30 2020 01:49:46 GMT+0300 (MSK) */


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int ui;

#pragma comment(linker, "/STACK:36777216")
//#pragma GCC optimize("O3")
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
#define double long double
#define ff first
#define ss second
#define int ll
#define fori(n) for (int i = 0; i < (n); i++)
#define forj(n) for (int j = 0; j < (n); j++)
#define endl "\n"

inline void boostIO() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cout.precision(10);
}
inline int safe_mul(int x, int y, int mod) {
	return x * 1LL * y % mod;
}

inline void safe_add(int& x, int y, int mod) {
	x += y;
	if (x >= mod)
		x -= mod;
}

const ll INF = 1e17;
const int modulo = 1e9 + 7;
const double EPS = 1e-7;
const double pi = 3.14159265358979323846;

int gcd(int a, int b)
{
	if (b == 0) return a;
	a %= b;
	return gcd(b, a);
}

int lcm(int a, int b) {
	return a * b / gcd(a, b);
}

int optpow(int a, int b, int k) {
	if (b == 0)
		return 1;
	int tmp = optpow(a, b / 2, k);
	if (b % 2 == 1) {
		return ((tmp*tmp) % k * a) % k;
	}
	else {
		return (tmp*tmp) % k;
	}
}

int qckpow(int a, int b) {
	if (b == 0)
		return 1;
	int tmp = qckpow(a, b / 2);
	if (b % 2 == 1) {
		return ((tmp*tmp) * a);
	}
	else {
		return (tmp*tmp);
	}
}

bool comp(pair<int, int> p1, pair<int, int> p2) {
	if (p1.ss == p2.ss)
		return p1.ff < p2.ff;
	return p1.ss < p2.ss;
}

const int maxn = 2e5 + 10;
vector<int> g[maxn];

int n, k;
int dp[maxn][5];
int dpth[maxn];
int temp[maxn][5];
int ans = 0;

void dfs1(int v, int p) {
	++dp[v][0];
	for (auto to : g[v]) {
		if (to == p)
			continue;
		dpth[to] = dpth[v] + 1;
		dfs1(to, v);
		fori(k) {
			dp[v][(i + 1) % k] += dp[to][i];
		}
	}
}

void dfs2(int v, int p, int curans, int t[5]) {
	ans += curans;
	for (auto to : g[v]) {
		if (to == p)
			continue;
		fori(k) {
			temp[to][i] += dp[to][i];
			temp[to][(i + 1) % k] += t[i] - dp[to][(i - 1 + k) % k];
		}
		dfs2(to, v, curans - dp[to][0] + t[0] - dp[to][k - 1], temp[to]);
	}
}

int32_t main() {
	boostIO();
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	cin >> n >> k;
	fori(n - 1) {
		int u, v;
		cin >> u >> v;
		g[u].push_back(v);
		g[v].push_back(u);
	}
	dfs1(1, -1);
	int curans = 0;
	fori(n) {
		int te = dpth[i + 1];
		curans += (te + k - 1) / k;
	}
	dfs2(1, -1, curans, dp[1]);
	cout << ans / 2;
}

/* Mon Mar 30 2020 01:56:27 GMT+0300 (MSK) */


    // Success is not final , failure is not fatal :
    //         it is the courage to continue that counts

#include <bits/stdc++.h>
using namespace std;
#define ff              first
#define ss              second
#define pb(x)           push_back(x)
#define mp              make_pair
#define sz(x)           x.size()
#define mem(x ,y)       memset(x , y , sizeof x )
#define all(a )         a.begin() , a.end()
#define endl            "\n"
#define pii             pair<int,int>
#define clr(x)          x.clear()
#define sl(x )          scanf("%I64d" ,&x)
#define si(x )          scanf("%d" ,&x)
#define forn(i ,x,n )   for(int i = x ; i <= n ; i++ )
#define ford(i ,x,n )   for(int i = x ; i >= n ; i-- )
#define rep(i,n )       for(int i= 0; i<n ; i++ )
#define repi(i,n )      for(int i= 1; i<=n ; i++ )
#define repit(i, c)     for( __typeof((c).begin()) i = (c).begin(); i != (c).end();++i )
#define dbg(args...)    do {   cerr << #args << ' ' ;  print(args); } while(0); cerr<< endl ;
typedef long long ll  ;
ll mod =  1e9+7, mod2 = 998244353 ;
typedef unsigned long long  ull ;
int setbit(int n, int pos  ) { return n = n|(1<< pos) ; }
int resetbit(int n,int pos ) {  return n =  n & ~(1<<pos ); }
bool checkbit(int  n,int pos ) { return (bool ) (n&(1<<pos))  ; }
template < typename T > T mul(T x, T y, T mod = mod ) { x %= mod ; y %= mod ; return (x*y)%mod  ;  }
template < typename T > T add(T x, T y, T mod = mod ) { x %= mod ; y %= mod ; return (x+y)%mod ;  }
template < typename T > T sub(T x, T y, T mod = mod ) { x %= mod ; y %= mod ; return ((x-y)%mod+mod )%mod;  }
template < typename T > T ext_gcd(T num1 , T num2, T &X , T &Y ) { T r2,r1, q2, q1 , x2, x1, y2 ,y1 , x,  y, r   ; x2 = 1; y2 = 0;  x1 = 0; y1 = 1; for( r2 =num1 ,r1 = num2 ;r1 != 0 ; y2 = y1, y1 = y,x2 = x1 ,x1 = x ,r2 = r1, r1 = r) {q1 = r2/r1; x = x2 - q1*x1; y = y2 - q1*y1; r = r2%r1 ; } X = x2 ; Y = y2 ; return r2 ;  }
template < typename T > void print(const T& v) {    cerr << v << ' ' ;}
template < typename T1, typename... T2 > void print( const T1& first, const T2&... rest ){ print(first); print(rest...) ;}
template<class T> string to_str(T t){stringstream ss; ss<<t; return ss.str();}
template < typename T >
T  bigmod(T x, T k ,T mod = mod) {
    if(k == 0 ) return (T)1;
    if(k&1  ) {
        return ( (x%mod)*bigmod(x,k-1, mod )%mod )%mod ;
    } else {
        T ret = bigmod(x,k/2  , mod ) ;
        ret %= mod ;
        return (ret*ret )%mod;
    }

}
template < typename T >
T  invmod( T x , T m) {
    return bigmod(x,m-2 , m) ;
    // long long ret, t ;//
    // ext_gcd( x, m ,ret ,t  ) ;
    // ret %= m ; if(ret<0) ret += m  ;
    // return ret;
}
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
// typedef tree<  int    ,     // change type
//               null_type,
//               less_equal  < int  >  ,  // change type ..
//               rb_tree_tag,
//               tree_order_statistics_node_update> ordered_set;
// debuging ...
template<typename T >
void dbg_a(T a[] ,int n=10 ) {
    cerr << "[ ";
        for(int i=0;i < n ; i++ )
            cerr<<a[i]<<' ' ;
                cerr<< " ]" <<  endl;
}
template < typename F,  typename S >
ostream& operator << ( ostream& os, const pair< F, S > & p ) {
    return os << "[ " << p.first << ", " << p.second << " ]";
}
template < typename T >
ostream &operator << ( ostream & os, const vector< T > &v ) {
    os << "[ ";
        for(int i=0; i<sz(v) ; i++ )
            os << v[i] << ' ' ;
                return os << " ]\n" ;
}
template < typename T >
ostream &operator << ( ostream & os, const map< T ,T> &Map  ) {
    os << "[ ";
        repit(it , Map )
            os << "[" <<(*it).ff << ' ' << (*it).ss << "] "    ;
                return os << "]\n" ;
}
template < typename T >
ostream &operator << ( ostream & os, const set< T > &Set  ) {
    os << "[ ";
        repit(it , Set )
            os <<  *it  << ' ' ;
                return os << " ]\n" ;
}
// int dy[] = {-1, +1,0 , 0 };
// int dx[ 10 ] =  {-2,-2, 2, 2  ,+ 1, -1  , +1, -1 }  ;
// int dy[ 10 ] =  {+1,-1, 1, -1 , +2,+2 , -2,-2  }  ;
const int maxn  = (int )1e6+123  ;
const ll inf  =  1e18+1223 ;
#define  int  ll
//////////////////////////////////////////////////////////////

int cnt[maxn ]  , dp[maxn ][10];
int n,  w  ,len , ans = 0, m ,   x ,y , k , p  ,tot  = 0  ,sum  ;
vector<int > g[maxn ] ;

void func(int  u , int p , int d) {
    d %= k ;
    dp[u][d ] = cnt[u]  = 1 ;

    rep( _ ,sz(  g[u] ) ) {
        int v = g[u][_]  ;
        if(v== p ) continue;
        func(v,u  , d+1 ) ;
        rep(i,  k )
            rep(j ,k) {
                int r , want ;
                r =  sub(i+j, 2*d,  k)  ;
                want =  sub(k,r, k )  ;

                ans += want*dp[u][i]*dp[v][j] ;

            }

        rep(i , k)
            dp[u][i] += dp[v][i] ;

        cnt[u] += cnt[v]  ;

    }

    ans +=  cnt[u ]*(n-cnt[u] )  ;  // taking the parent edge

}
void solve( ) {
    cin >> n >> k;
    rep(i ,n -1) {
        cin >> x >> y  ;
        g[x].pb(y) ;
        g[y].pb(x) ;
    }

    func(1 ,0,0 ) ;
    // dbg(ans  , k) ;
    cout << ans /k << endl;

}
signed main() {
    #ifndef ONLINE_JUDGE
       freopen("in.txt", "r", stdin);
          // freopen("out.tx    t", "w", stdout);
    #endif
    ios :: sync_with_stdio(false);  cin.tie(0);
    cout.tie(0) ;
    clock_t st = clock() ;
    // cout << fixed << setprecision(12) ;
    int  c = 0 ,t = 1 ;
    // cin  >> a >> b ;
    // cin>>t ;
    while(t--) {
        solve()  ;
    }
    // cerr << "Execution time : " << (double  )  (clock()-st )/CLOCKS_PER_SEC << endl ;
    // 12m476 ~473      11

    return 0 ;

}


#pragma GCC optimize("Ofast")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#include <bits/stdc++.h>
/*#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>*/

#define pll              pair <long long,long long>
#define pb               push_back
#define ll               long long
#define ff               first
#define ss               second
#define D(x)             cerr<<#x " = "<<(x)<<endl
#define vll              vector <ll>
#define IOS              ios_base::sync_with_stdio(0); cin.tie(NULL);
#define endl             '\n'
using namespace std;
const ll N = 2e5+2;
const ll K = 6;
vector<ll>g[N];
ll dp[N][K];
ll sze[N];
ll wh[N];
ll n,k;
ll ans=0;

void dfs(ll v,ll par)
{
	// cout<<v<<" _________"<<endl;
	ll cnt[k]={0};
	sze[v]=1LL;
	cnt[0]=1LL;
	dp[v][0]=1LL;
	for(ll x:g[v])
	{
		if(x!=par)
		{
			dfs(x,v);
			for(ll i=0;i<k;i++)
			{
				ll val = (i+1)%k;
				cnt[val]+=dp[x][i];
			}
			for(ll i=0;i<k;i++)
			{
				for(ll j=0;j<k;j++)
				{
					ll rem=(i+j+1)/k + ((i+j+1)%k != 0LL);
					ans+=dp[v][i]*dp[x][j]*rem;
				}
			}
			ans+=wh[x]*sze[v] + wh[v]*sze[x];
			for(ll i=0;i<k;i++)
			{
				dp[v][i]=cnt[i];
				//cout<<v<<" "<<x<<" "<<i<<" "<<cnt[i]<<endl;
			}
			wh[v]+=wh[x];
			wh[v]+=dp[x][k-1];
			sze[v]+=sze[x];
			// cout<<v<<" "<<x<<" "<<wh[v]<<endl;
		}
	}
}

int main()
{
    IOS
 	// freopen("input.txt","r",stdin);
 	// freopen("output.txt","w",stdout);
 	// freopen("error.txt","w",stderr);
 	memset(dp,0,sizeof(dp));
 	memset(wh,0,sizeof(wh));
 	cin>>n>>k;
 	for(ll i=0;i<n-1;i++)
 	{
 		ll a,b;
 		cin>>a>>b;
 		g[a].push_back(b);
 		g[b].push_back(a);
 	}
 	dfs(1,0);
 	cout<<ans<<endl;
    return 0;
}


#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define int long long
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

vector<vector<int> >adj;
int dis[200006][5];
int cnt[200005][5];
int n,k;
int ans=0;
int chin=0;
void dfs(int ver,int p)
{
   for(auto i:adj[ver])
   {
      if(i!=p)
      {
         dfs(i,ver);
         for(int j=0;j<k;j++)
         {
            dis[ver][j]+=dis[i][(j-1+k)%k]+cnt[i][(j-1+k)%k];
            cnt[ver][j]+=cnt[i][(j-1+k)%k];
         }
      }
   }

   for(auto i:adj[ver])
   {
      if(i!=p)
      {
         for(int j=0;j<k;j++)
         {
            int zz1=dis[ver][j]-dis[i][(j-1+k)%k]-cnt[i][(j-1+k)%k];
            int zz2=cnt[ver][j]-cnt[i][(j-1+k)%k];

            for(int l=0;l<k;l++)
            {
            int zz=dis[i][(l-1+k)%k]+cnt[i][(l-1+k)%k];
            int dd=zz1*cnt[i][(l-1+k)%k]+zz*zz2;
            int xx=(j+l)%k;
            xx=(k-xx)%k;
            dd+=xx*zz2*cnt[i][(l-1+k)%k];
            ans+=dd/k;
            }
         }
      }
   }
   for(int j=0;j<k;j++)
   {
            int zz=dis[ver][(j)%k];
            int xx=(k-j)%k;
            zz+=cnt[ver][(j)%k]*xx;
            chin+=zz/k;
   }

   cnt[ver][0]++;
}

signed main()
{
     ios_base::sync_with_stdio(false);
     cin.tie(NULL);
 #ifndef ONLINE_JUDGE
    freopen ("INPUT.txt" , "r" , stdin);
    freopen ("OUTPUT.txt" , "w" , stdout);
 #endif

// -------------------------------------Code starts here---------------------------------------------------------------------

   cin>>n>>k;
   adj.resize(n+1);
   int x,y;
   for(int i=0;i<n-1;i++)
   {
      cin>>x>>y;
      adj[x].push_back(y);
      adj[y].push_back(x);
   }
   dfs(1,0);
   cout<<ans/2+chin;

// -------------------------------------Code ends here------------------------------------------------------------------
     clock_t clk;
 	clk = clock();

    clk = clock() - clk;
 	cerr << fixed << setprecision(6) << "Time: " << ((double)clk)/CLOCKS_PER_SEC << "\n";
 	return 0;
 }


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

/* emaxx implementation */
/* Multiplication with arbitrary modulos
 *    use ntt if mod is prime and can be written as 2**k * c + 1
 *    if not, use Chinese Reminder Theorem
 *    or transform A(x) = A1(x) + A2(x)*c decompose into A(x)/c and A(x)%c
 *                 B(x) = B1(x) + B2(x)*c
 *        where c ~= sqrt(mod)
 *        A * B = A1*B1 + c*(A1*B2 + A2*B1) * c**2(A2*B2)
 *        with all values < sqrt(mod) subpolynomials have coefficientes < mod * N after fft multiply decreasing changes of rounding error
 * */

const double PI=acos(-1);
typedef complex<double> base;
inline void fft (vector<base> & a, bool invert) {
    int n=(int) a.size();
    for (int i=1, j=0; i<n; ++i) {
        int bit=n>>1;
        for (;j>=bit;bit>>=1)
            j-=bit;
        j+=bit;
        if(i<j)
            swap(a[i],a[j]);
    }
    for (int len=2; len<=n; len<<=1) {
        double ang = 2*PI/len * (invert ? -1 : 1);
        base wlen(cos(ang), sin(ang));
        for (int i=0; i<n; i+=len) {
            base w(1);
            for (int j=0; j<len/2; ++j) {
                base u=a[i+j], v=a[i+j+len/2]*w;
                a[i+j]=u+v;
                a[i+j+len/2]=u-v;
                w*=wlen;
            }
        }
    }
    if (invert)
        for(int i=0;i<n;++i)
            a[i]/=n;
}

// a, b => coefs to multiply,  res => resulting coefs
// a[0], b[0], res[0] = coef x^0
inline void multiply (const vector<int> & a, const vector<int> & b, vector<int> & res) {//change res to ll if needed
    if(a.size() * b.size() <= 256) {
        res.resize(a.size() + b.size(), 0);
        for(int i = 0; i < (int)a.size(); i++)
            for(int j = 0; j < (int)b.size(); j++)
                res[i + j] += 1LL * a[i] * b[j];
        return;
    }
    vector<base> fa (a.begin(), a.end()),  fb (b.begin(), b.end());
    size_t n=1;
    while (n<max(a.size(),b.size())) n<<=1;
    n<<=1;
    fa.resize(n),fb.resize(n);
    fft (fa,false);  fft(fb,false);
    for (size_t i=0; i<n; ++i)
        fa[i]*=fb[i];
    fft (fa, true);
    res.resize (n);
    for(size_t i=0; i<n; ++i)
        res[i]=(int)(fa[i].real()>0 ? fa[i].real()+0.5 : fa[i].real()-0.5);
    while(res.size()&&res.back()==0) res.pop_back();
}

const int Max = 1e6+10;
int n, sizes[Max];
vector<int> adj[Max], cntPathLength[Max];
ll prod[Max], cntTotalPathLengths[Max] = {0}, cntTotalPathLengthsNaive[Max] = {0};
bool removed[Max];

void dfs2(int node, int par, int root, int currDist) {
    while(cntPathLength[root].size() <= currDist) {
        cntPathLength[root].push_back(0);
    }
    cntPathLength[root][currDist]++;
    sizes[node] = 1;
    for(int to : adj[node]) {
        if(to != par && !removed[to]) {
            dfs2(to, node, root, currDist+1);
            sizes[node] += sizes[to];
        }
    }
}

int findCentroid(int node) {
    dfs2(node, node, node, 1);
    bool found = true;
    int sizeCap = sizes[node]/2;
    int par = node;
    while(found) {
        found = false;
        for(int to : adj[node]) {
            if(to != par && !removed[to] && sizes[to] > sizeCap) {
                found = true;
                par = node;
                node = to;
                break;
            }
        }
    }
    return node;
}

void dfs1(int node, int par) {
    removed[node] = true;
    int maxLength = 1;
    for(int to : adj[node]) {
        if(to != par && !removed[to]) {
            cntPathLength[to].clear();
            cntPathLength[to].push_back(0);
            dfs2(to, to, to, 1);
            maxLength = max(maxLength, (int)cntPathLength[to].size());
        }
    }
    vector<int> temp(maxLength, 0);
    temp[0]++;
    for(int to : adj[node]) {
        if(to != par && !removed[to]) {
            vector<int> prod;
            multiply(temp, cntPathLength[to], prod);
            for(int i = 0; i < prod.size(); ++i) {
                cntTotalPathLengths[i] += prod[i];
            }
            for(int i = 0; i < cntPathLength[to].size(); ++i) {
                temp[i] += cntPathLength[to][i];
            }
        }
    }

    for(int to : adj[node]) {
        if(to != par && !removed[to]) {
            dfs1(findCentroid(to), node);
        }
    }
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n,k;
    cin >> n >> k;
    for(int i=0;i<n-1;++i){
        int u,v;
        cin >> u >> v;
        adj[u].push_back(v);
        adj[v].push_back(u);
    }
    dfs1(findCentroid(1), 0);
    ll res = 0;
    for(int i=0;i<=n;++i){
        res += 1LL*cntTotalPathLengths[i]*((i+k-1)/k);
    }
    cout << res;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

/* emaxx implementation */
/* Multiplication with arbitrary modulos
 *    use ntt if mod is prime and can be written as 2**k * c + 1
 *    if not, use Chinese Reminder Theorem
 *    or transform A(x) = A1(x) + A2(x)*c decompose into A(x)/c and A(x)%c
 *                 B(x) = B1(x) + B2(x)*c
 *        where c ~= sqrt(mod)
 *        A * B = A1*B1 + c*(A1*B2 + A2*B1) * c**2(A2*B2)
 *        with all values < sqrt(mod) subpolynomials have coefficientes < mod * N after fft multiply decreasing changes of rounding error
 * */

const double PI=acos(-1);
typedef complex<double> base;
inline void fft (vector<base> & a, bool invert) {
    int n=(int) a.size();
    for (int i=1, j=0; i<n; ++i) {
        int bit=n>>1;
        for (;j>=bit;bit>>=1)
            j-=bit;
        j+=bit;
        if(i<j)
            swap(a[i],a[j]);
    }
    for (int len=2; len<=n; len<<=1) {
        double ang = 2*PI/len * (invert ? -1 : 1);
        base wlen(cos(ang), sin(ang));
        for (int i=0; i<n; i+=len) {
            base w(1);
            for (int j=0; j<len/2; ++j) {
                base u=a[i+j], v=a[i+j+len/2]*w;
                a[i+j]=u+v;
                a[i+j+len/2]=u-v;
                w*=wlen;
            }
        }
    }
    if (invert)
        for(int i=0;i<n;++i)
            a[i]/=n;
}

// a, b => coefs to multiply,  res => resulting coefs
// a[0], b[0], res[0] = coef x^0
inline void multiply (const vector<int> & a, const vector<int> & b, vector<int> & res) {//change res to ll if needed
    if(a.size() * b.size() <= 256) {
        res.resize(a.size() + b.size(), 0);
        for(int i = 0; i < (int)a.size(); i++)
            for(int j = 0; j < (int)b.size(); j++)
                res[i + j] += 1LL * a[i] * b[j];
        return;
    }
    vector<base> fa (a.begin(), a.end()),  fb (b.begin(), b.end());
    size_t n=1;
    while (n<max(a.size(),b.size())) n<<=1;
    n<<=1;
    fa.resize(n),fb.resize(n);
    fft (fa,false);  fft(fb,false);
    for (size_t i=0; i<n; ++i)
        fa[i]*=fb[i];
    fft (fa, true);
    res.resize (n);
    for(size_t i=0; i<n; ++i)
        res[i]=(int)(fa[i].real()>0 ? fa[i].real()+0.5 : fa[i].real()-0.5);
}

const int Max = 1e6+10;
int n, sizes[Max];
vector<int> adj[Max], cntPathLength[Max];
ll prod[Max], cntTotalPathLengths[Max] = {0}, cntTotalPathLengthsNaive[Max] = {0};
bool removed[Max];

void dfs2(int node, int par, int root, int currDist) {
    if(cntPathLength[root].size() <= currDist) {
        cntPathLength[root].push_back(0);
    }
    cntPathLength[root][currDist]++;
    sizes[node] = 1;
    for(int to : adj[node]) {
        if(to != par && !removed[to]) {
            dfs2(to, node, root, currDist+1);
            sizes[node] += sizes[to];
        }
    }
}

int findCentroid(int node) {
    dfs2(node, node, node, 1);
    bool found = true;
    int sizeCap = sizes[node]/2;
    int par = node;
    while(found) {
        found = false;
        for(int to : adj[node]) {
            if(to != par && !removed[to] && sizes[to] > sizeCap) {
                found = true;
                par = node;
                node = to;
                break;
            }
        }
    }
    return node;
}

void dfs1(int node, int par) {
    removed[node] = true;
    int maxLength = 1;
    for(int to : adj[node]) {
        if(to != par && !removed[to]) {
            cntPathLength[to].clear();
            cntPathLength[to].push_back(0);
            dfs2(to, to, to, 1);
            maxLength = max(maxLength, (int)cntPathLength[to].size());
        }
    }
    vector<int> temp(maxLength, 0);
    temp[0]++;
    for(int to : adj[node]) {
        if(to != par && !removed[to]) {
            vector<int> prod;
            multiply(temp, cntPathLength[to], prod);
            for(int i = 0; i < prod.size(); ++i) {
                cntTotalPathLengths[i] += prod[i];
            }
            for(int i = 0; i < cntPathLength[to].size(); ++i) {
                temp[i] += cntPathLength[to][i];
            }
        }
    }

    for(int to : adj[node]) {
        if(to != par && !removed[to]) {
            dfs1(findCentroid(to), node);
        }
    }
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n,k;
    cin >> n >> k;
    for(int i=0;i<n-1;++i){
        int u,v;
        cin >> u >> v;
        adj[u].push_back(v);
        adj[v].push_back(u);
    }
    dfs1(findCentroid(1), 0);
    int res = 0;
    for(int i=0;i<=n;++i){
        res += cntTotalPathLengths[i]*((i+k-1)/k);
    }
    cout << res;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

/* emaxx implementation */
/* Multiplication with arbitrary modulos
 *    use ntt if mod is prime and can be written as 2**k * c + 1
 *    if not, use Chinese Reminder Theorem
 *    or transform A(x) = A1(x) + A2(x)*c decompose into A(x)/c and A(x)%c
 *                 B(x) = B1(x) + B2(x)*c
 *        where c ~= sqrt(mod)
 *        A * B = A1*B1 + c*(A1*B2 + A2*B1) * c**2(A2*B2)
 *        with all values < sqrt(mod) subpolynomials have coefficientes < mod * N after fft multiply decreasing changes of rounding error
 * */

const double PI=acos(-1);
typedef complex<double> base;
inline void fft (vector<base> & a, bool invert) {
    int n=(int) a.size();
    for (int i=1, j=0; i<n; ++i) {
        int bit=n>>1;
        for (;j>=bit;bit>>=1)
            j-=bit;
        j+=bit;
        if(i<j)
            swap(a[i],a[j]);
    }
    for (int len=2; len<=n; len<<=1) {
        double ang = 2*PI/len * (invert ? -1 : 1);
        base wlen(cos(ang), sin(ang));
        for (int i=0; i<n; i+=len) {
            base w(1);
            for (int j=0; j<len/2; ++j) {
                base u=a[i+j], v=a[i+j+len/2]*w;
                a[i+j]=u+v;
                a[i+j+len/2]=u-v;
                w*=wlen;
            }
        }
    }
    if (invert)
        for(int i=0;i<n;++i)
            a[i]/=n;
}

// a, b => coefs to multiply,  res => resulting coefs
// a[0], b[0], res[0] = coef x^0
inline void multiply (const vector<int> & a, const vector<int> & b, vector<int> & res) {//change res to ll if needed
    if(a.size() * b.size() <= 256) {
        res.resize(a.size() + b.size(), 0);
        for(int i = 0; i < (int)a.size(); i++)
            for(int j = 0; j < (int)b.size(); j++)
                res[i + j] += 1LL * a[i] * b[j];
        return;
    }
    vector<base> fa (a.begin(), a.end()),  fb (b.begin(), b.end());
    size_t n=1;
    while (n<max(a.size(),b.size())) n<<=1;
    n<<=1;
    fa.resize(n),fb.resize(n);
    fft (fa,false);  fft(fb,false);
    for (size_t i=0; i<n; ++i)
        fa[i]*=fb[i];
    fft (fa, true);
    res.resize (n);
    for(size_t i=0; i<n; ++i)
        res[i]=(int)(fa[i].real()>0 ? fa[i].real()+0.5 : fa[i].real()-0.5);
}

const int Max = 1e6+10;
int n, sizes[Max];
vector<int> adj[Max], cntPathLength[Max];
ll prod[Max], cntTotalPathLengths[Max] = {0}, cntTotalPathLengthsNaive[Max] = {0};
bool removed[Max];

void dfs2(int node, int par, int root, int currDist) {
    while(cntPathLength[root].size() <= currDist) {
        cntPathLength[root].push_back(0);
    }
    cntPathLength[root][currDist]++;
    sizes[node] = 1;
    for(int to : adj[node]) {
        if(to != par && !removed[to]) {
            dfs2(to, node, root, currDist+1);
            sizes[node] += sizes[to];
        }
    }
}

int findCentroid(int node) {
    dfs2(node, node, node, 1);
    bool found = true;
    int sizeCap = sizes[node]/2;
    int par = node;
    while(found) {
        found = false;
        for(int to : adj[node]) {
            if(to != par && !removed[to] && sizes[to] > sizeCap) {
                found = true;
                par = node;
                node = to;
                break;
            }
        }
    }
    return node;
}

void dfs1(int node, int par) {
    removed[node] = true;
    int maxLength = 1;
    for(int to : adj[node]) {
        if(to != par && !removed[to]) {
            cntPathLength[to].clear();
            cntPathLength[to].push_back(0);
            dfs2(to, to, to, 1);
            maxLength = max(maxLength, (int)cntPathLength[to].size());
        }
    }
    vector<int> temp(maxLength, 0);
    temp[0]++;
    for(int to : adj[node]) {
        if(to != par && !removed[to]) {
            vector<int> prod;
            multiply(temp, cntPathLength[to], prod);
            for(int i = 0; i < prod.size(); ++i) {
                cntTotalPathLengths[i] += prod[i];
            }
            for(int i = 0; i < cntPathLength[to].size(); ++i) {
                temp[i] += cntPathLength[to][i];
            }
        }
    }

    for(int to : adj[node]) {
        if(to != par && !removed[to]) {
            dfs1(findCentroid(to), node);
        }
    }
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n,k;
    cin >> n >> k;
    for(int i=0;i<n-1;++i){
        int u,v;
        cin >> u >> v;
        adj[u].push_back(v);
        adj[v].push_back(u);
    }
    dfs1(findCentroid(1), 0);
    int res = 0;
    for(int i=0;i<=n;++i){
        res += cntTotalPathLengths[i]*((i+k-1)/k);
    }
    cout << res;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

/* emaxx implementation */
/* Multiplication with arbitrary modulos
 *    use ntt if mod is prime and can be written as 2**k * c + 1
 *    if not, use Chinese Reminder Theorem
 *    or transform A(x) = A1(x) + A2(x)*c decompose into A(x)/c and A(x)%c
 *                 B(x) = B1(x) + B2(x)*c
 *        where c ~= sqrt(mod)
 *        A * B = A1*B1 + c*(A1*B2 + A2*B1) * c**2(A2*B2)
 *        with all values < sqrt(mod) subpolynomials have coefficientes < mod * N after fft multiply decreasing changes of rounding error
 * */

const double PI=acos(-1);
typedef complex<double> base;
inline void fft (vector<base> & a, bool invert) {
    int n=(int) a.size();
    for (int i=1, j=0; i<n; ++i) {
        int bit=n>>1;
        for (;j>=bit;bit>>=1)
            j-=bit;
        j+=bit;
        if(i<j)
            swap(a[i],a[j]);
    }
    for (int len=2; len<=n; len<<=1) {
        double ang = 2*PI/len * (invert ? -1 : 1);
        base wlen(cos(ang), sin(ang));
        for (int i=0; i<n; i+=len) {
            base w(1);
            for (int j=0; j<len/2; ++j) {
                base u=a[i+j], v=a[i+j+len/2]*w;
                a[i+j]=u+v;
                a[i+j+len/2]=u-v;
                w*=wlen;
            }
        }
    }
    if (invert)
        for(int i=0;i<n;++i)
            a[i]/=n;
}

// a, b => coefs to multiply,  res => resulting coefs
// a[0], b[0], res[0] = coef x^0
inline void multiply (const vector<int> & a, const vector<int> & b, vector<int> & res) {//change res to ll if needed
    if(a.size() * b.size() <= 256) {
        res.resize(a.size() + b.size(), 0);
        for(int i = 0; i < (int)a.size(); i++)
            for(int j = 0; j < (int)b.size(); j++)
                res[i + j] += 1LL * a[i] * b[j];
        while(res.size() && res.back() == 0) res.pop_back();
        return;
    }
    vector<base> fa (a.begin(), a.end()),  fb (b.begin(), b.end());
    size_t n=1;
    while (n<max(a.size(),b.size())) n<<=1;
    n<<=1;
    fa.resize(n),fb.resize(n);
    fft (fa,false);  fft(fb,false);
    for (size_t i=0; i<n; ++i)
        fa[i]*=fb[i];
    fft (fa, true);
    res.resize (n);
    for(size_t i=0; i<n; ++i)
        res[i]=(int)(fa[i].real()>0 ? fa[i].real()+0.5 : fa[i].real()-0.5);
    while(res.size() && res.back() == 0) res.pop_back();
}

const int Max = 2e5+10;
int n, sizes[Max];
vector<int> adj[Max], cntPathLength[Max];
ll cntTotalPathLengths[Max];
bool removed[Max];

void dfs2(int node, int par, int root, int currDist) {
    while(cntPathLength[root].size() <= currDist) {
        cntPathLength[root].push_back(0);
    }
    cntPathLength[root][currDist]++;
    sizes[node] = 1;
    for(int to : adj[node]) {
        if(to != par && !removed[to]) {
            dfs2(to, node, root, currDist+1);
            sizes[node] += sizes[to];
        }
    }
}

int findCentroid(int node) {
    dfs2(node, node, node, 1);
    bool found = true;
    int sizeCap = sizes[node]/2;
    int par = node;
    while(found) {
        found = false;
        for(int to : adj[node]) {
            if(to != par && !removed[to] && sizes[to] > sizeCap) {
                found = true;
                par = node;
                node = to;
                break;
            }
        }
    }
    return node;
}

void dfs1(int node, int par) {
    removed[node] = true;
    int maxLength = 1;
    for(int to : adj[node]) {
        if(to != par && !removed[to]) {
            cntPathLength[to].clear();
            cntPathLength[to].push_back(0);
            dfs2(to, to, to, 1);
            maxLength = max(maxLength, (int)cntPathLength[to].size());
        }
    }
    vector<int> temp(maxLength, 0);
    temp[0]++;
    for(int to : adj[node]) {
        if(to != par && !removed[to]) {
            vector<int> prod;
            multiply(temp, cntPathLength[to], prod);
            for(int i = 0; i < prod.size(); ++i) {
                cntTotalPathLengths[i] += prod[i];
            }
            for(int i = 0; i < cntPathLength[to].size(); ++i) {
                temp[i] += cntPathLength[to][i];
            }
        }
    }

    for(int to : adj[node]) {
        if(to != par && !removed[to]) {
            dfs1(findCentroid(to), node);
        }
    }
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n,k;
    cin >> n >> k;
    for(int i=0;i<n-1;++i){
        int u,v;
        cin >> u >> v;
        adj[u].push_back(v);
        adj[v].push_back(u);
    }
    dfs1(findCentroid(1), 0);
    ll res = 0;
    for(int i=0;i<=n;++i){
        res += 1LL*cntTotalPathLengths[i]*((i+k-1)/k);
    }
    cout << res;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

/* emaxx implementation */
/* Multiplication with arbitrary modulos
 *    use ntt if mod is prime and can be written as 2**k * c + 1
 *    if not, use Chinese Reminder Theorem
 *    or transform A(x) = A1(x) + A2(x)*c decompose into A(x)/c and A(x)%c
 *                 B(x) = B1(x) + B2(x)*c
 *        where c ~= sqrt(mod)
 *        A * B = A1*B1 + c*(A1*B2 + A2*B1) * c**2(A2*B2)
 *        with all values < sqrt(mod) subpolynomials have coefficientes < mod * N after fft multiply decreasing changes of rounding error
 * */

const double PI=acos(-1);
typedef complex<double> base;
inline void fft (vector<base> & a, bool invert) {
    int n=(int) a.size();
    for (int i=1, j=0; i<n; ++i) {
        int bit=n>>1;
        for (;j>=bit;bit>>=1)
            j-=bit;
        j+=bit;
        if(i<j)
            swap(a[i],a[j]);
    }
    for (int len=2; len<=n; len<<=1) {
        double ang = 2*PI/len * (invert ? -1 : 1);
        base wlen(cos(ang), sin(ang));
        for (int i=0; i<n; i+=len) {
            base w(1);
            for (int j=0; j<len/2; ++j) {
                base u=a[i+j], v=a[i+j+len/2]*w;
                a[i+j]=u+v;
                a[i+j+len/2]=u-v;
                w*=wlen;
            }
        }
    }
    if (invert)
        for(int i=0;i<n;++i)
            a[i]/=n;
}

// a, b => coefs to multiply,  res => resulting coefs
// a[0], b[0], res[0] = coef x^0
inline void multiply (const vector<int> & a, const vector<int> & b, vector<int> & res) {//change res to ll if needed
    if(a.size() * b.size() <= 256) {
        res.resize(a.size() + b.size(), 0);
        for(int i = 0; i < (int)a.size(); i++)
            for(int j = 0; j < (int)b.size(); j++)
                res[i + j] += 1LL * a[i] * b[j];
        while(res.size()&&res.back()==0) res.pop_back();
        return;
    }
    vector<base> fa (a.begin(), a.end()),  fb (b.begin(), b.end());
    size_t n=1;
    while (n<max(a.size(),b.size())) n<<=1;
    n<<=1;
    fa.resize(n),fb.resize(n);
    fft (fa,false);  fft(fb,false);
    for (size_t i=0; i<n; ++i)
        fa[i]*=fb[i];
    fft (fa, true);
    res.resize (n);
    for(size_t i=0; i<n; ++i)
        res[i]=(int)(fa[i].real()>0 ? fa[i].real()+0.5 : fa[i].real()-0.5);
    while(res.size()&&res.back()==0) res.pop_back();
}

const int Max = 1e6+10;
int n, sizes[Max];
vector<int> adj[Max], cntPathLength[Max];
ll prod[Max], cntTotalPathLengths[Max] = {0}, cntTotalPathLengthsNaive[Max] = {0};
bool removed[Max];

void dfs2(int node, int par, int root, int currDist) {
    while(cntPathLength[root].size() <= currDist) {
        cntPathLength[root].push_back(0);
    }
    cntPathLength[root][currDist]++;
    sizes[node] = 1;
    for(int to : adj[node]) {
        if(to != par && !removed[to]) {
            dfs2(to, node, root, currDist+1);
            sizes[node] += sizes[to];
        }
    }
}

int findCentroid(int node) {
    dfs2(node, node, node, 1);
    bool found = true;
    int sizeCap = sizes[node]/2;
    int par = node;
    while(found) {
        found = false;
        for(int to : adj[node]) {
            if(to != par && !removed[to] && sizes[to] > sizeCap) {
                found = true;
                par = node;
                node = to;
                break;
            }
        }
    }
    return node;
}

void dfs1(int node, int par) {
    removed[node] = true;
    int maxLength = 1;
    for(int to : adj[node]) {
        if(to != par && !removed[to]) {
            cntPathLength[to].clear();
            cntPathLength[to].push_back(0);
            dfs2(to, to, to, 1);
            maxLength = max(maxLength, (int)cntPathLength[to].size());
        }
    }
    vector<int> temp(maxLength, 0);
    temp[0]++;
    for(int to : adj[node]) {
        if(to != par && !removed[to]) {
            vector<int> prod;
            multiply(temp, cntPathLength[to], prod);
            for(int i = 0; i < prod.size(); ++i) {
                cntTotalPathLengths[i] += prod[i];
            }
            for(int i = 0; i < cntPathLength[to].size(); ++i) {
                temp[i] += cntPathLength[to][i];
            }
        }
    }

    for(int to : adj[node]) {
        if(to != par && !removed[to]) {
            dfs1(findCentroid(to), node);
        }
    }
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n,k;
    cin >> n >> k;
    for(int i=0;i<n-1;++i){
        int u,v;
        cin >> u >> v;
        adj[u].push_back(v);
        adj[v].push_back(u);
    }
    dfs1(findCentroid(1), 0);
    ll res = 0;
    for(int i=0;i<=n;++i){
        res += 1LL*cntTotalPathLengths[i]*((i+k-1)/k);
    }
    cout << res;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

/* emaxx implementation */
/* Multiplication with arbitrary modulos
 *    use ntt if mod is prime and can be written as 2**k * c + 1
 *    if not, use Chinese Reminder Theorem
 *    or transform A(x) = A1(x) + A2(x)*c decompose into A(x)/c and A(x)%c
 *                 B(x) = B1(x) + B2(x)*c
 *        where c ~= sqrt(mod)
 *        A * B = A1*B1 + c*(A1*B2 + A2*B1) * c**2(A2*B2)
 *        with all values < sqrt(mod) subpolynomials have coefficientes < mod * N after fft multiply decreasing changes of rounding error
 * */

const double PI=acos(-1);
typedef complex<double> base;
inline void fft (vector<base> & a, bool invert) {
    int n=(int) a.size();
    for (int i=1, j=0; i<n; ++i) {
        int bit=n>>1;
        for (;j>=bit;bit>>=1)
            j-=bit;
        j+=bit;
        if(i<j)
            swap(a[i],a[j]);
    }
    for (int len=2; len<=n; len<<=1) {
        double ang = 2*PI/len * (invert ? -1 : 1);
        base wlen(cos(ang), sin(ang));
        for (int i=0; i<n; i+=len) {
            base w(1);
            for (int j=0; j<len/2; ++j) {
                base u=a[i+j], v=a[i+j+len/2]*w;
                a[i+j]=u+v;
                a[i+j+len/2]=u-v;
                w*=wlen;
            }
        }
    }
    if (invert)
        for(int i=0;i<n;++i)
            a[i]/=n;
}

// a, b => coefs to multiply,  res => resulting coefs
// a[0], b[0], res[0] = coef x^0
inline void multiply (const vector<int> & a, const vector<int> & b, vector<int> & res) {//change res to ll if needed
    if(a.size() * b.size() <= 256) {
        res.resize(a.size() + b.size(), 0);
        for(int i = 0; i < (int)a.size(); i++)
            for(int j = 0; j < (int)b.size(); j++)
                res[i + j] += 1LL * a[i] * b[j];
        return;
    }
    vector<base> fa (a.begin(), a.end()),  fb (b.begin(), b.end());
    size_t n=1;
    while (n<max(a.size(),b.size())) n<<=1;
    n<<=1;
    fa.resize(n),fb.resize(n);
    fft (fa,false);  fft(fb,false);
    for (size_t i=0; i<n; ++i)
        fa[i]*=fb[i];
    fft (fa, true);
    res.resize (n);
    for(size_t i=0; i<n; ++i)
        res[i]=(int)(fa[i].real()>0 ? fa[i].real()+0.5 : fa[i].real()-0.5);
}

const int Max = 1e6+10;
int n, sizes[Max];
vector<int> adj[Max], cntPathLength[Max];
ll prod[Max], cntTotalPathLengths[Max] = {0}, cntTotalPathLengthsNaive[Max] = {0};
bool removed[Max];

void dfs2(int node, int par, int root, int currDist) {
    while(cntPathLength[root].size() <= currDist) {
        cntPathLength[root].push_back(0);
    }
    cntPathLength[root][currDist]++;
    sizes[node] = 1;
    for(int to : adj[node]) {
        if(to != par && !removed[to]) {
            dfs2(to, node, root, currDist+1);
            sizes[node] += sizes[to];
        }
    }
}

int findCentroid(int node) {
    dfs2(node, node, node, 1);
    bool found = true;
    int sizeCap = sizes[node]/2;
    int par = node;
    while(found) {
        found = false;
        for(int to : adj[node]) {
            if(to != par && !removed[to] && sizes[to] > sizeCap) {
                found = true;
                par = node;
                node = to;
                break;
            }
        }
    }
    return node;
}

void dfs1(int node, int par) {
    removed[node] = true;
    int maxLength = 1;
    for(int to : adj[node]) {
        if(to != par && !removed[to]) {
            cntPathLength[to].clear();
            cntPathLength[to].push_back(0);
            dfs2(to, to, to, 1);
            maxLength = max(maxLength, (int)cntPathLength[to].size());
        }
    }
    vector<int> temp(maxLength, 0);
    temp[0]++;
    for(int to : adj[node]) {
        if(to != par && !removed[to]) {
            vector<int> prod;
            multiply(temp, cntPathLength[to], prod);
            for(int i = 0; i < prod.size(); ++i) {
                cntTotalPathLengths[i] += prod[i];
            }
            for(int i = 0; i < cntPathLength[to].size(); ++i) {
                temp[i] += cntPathLength[to][i];
            }
        }
    }

    for(int to : adj[node]) {
        if(to != par && !removed[to]) {
            dfs1(findCentroid(to), node);
        }
    }
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n,k;
    cin >> n >> k;
    for(int i=0;i<n-1;++i){
        int u,v;
        cin >> u >> v;
        adj[u].push_back(v);
        adj[v].push_back(u);
    }
    dfs1(findCentroid(1), 0);
    ll res = 0;
    for(int i=0;i<=n;++i){
        res += 1LL*cntTotalPathLengths[i]*((i+k-1)/k);
    }
    cout << res;
}


#include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
typedef long long ll;

const int N = 2e5+5;
vector<int> adj[N];
int dp[5];
int subSize[N];
int n,k;

vector<int> dfs(int node, int par) {
    subSize[node] = 1;
    vector<int> numPathsCurr(k,0);
    ++numPathsCurr[0];
    for(int child : adj[node]) {
        if(child == par) continue;
        vector<int> numPaths = dfs(child, node);
        subSize[node] += subSize[child];

        vector<int> temp;
        temp.push_back(numPaths.back());
        for(int i=0;i+1<numPaths.size();++i){
            temp.push_back(numPaths[i]);
        }
        numPaths = temp;

        for(int i=0;i<k;++i){
            for(int j=0;j<k;++j){
                dp[(i+j)%k] += numPaths[i]*numPathsCurr[j];
            }
        }

        for(int i=0;i<k;++i){
            numPathsCurr[i] += numPaths[i];
        }
    }
    return numPathsCurr;
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> n >> k;
    for(int i=0;i<n-1;++i){
        int u,v;
        cin >> u >> v;
        adj[u].push_back(v);
        adj[v].push_back(u);
    }
    dfs(1,1);
    int res = 0;
    for(int i=1;i<=n;++i){
        res += subSize[i] * (n - subSize[i]);
    }
    for(int i=0;i<k;++i){
        res += dp[i]*((k-i)%k);
    }
    cout << res/k;
}


#pragma GCC optimize ("Ofast")

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>

using namespace __gnu_pbds;
using namespace __gnu_cxx;
using namespace std;

#define int long long
#define double long double
#define Int signed
#define vi vector<int>
#define vvi vector<vi>
#define vd vector<double>
#define vvd vector<vd>
#define pii pair<int, int>
#define vpii vector<pii>
#define vvpii vector<vpii>
#define mii map<int, int>
#define unordered_map gp_hash_table

#define OVERLOADED_MACRO(M, ...) _OVR(M, _COUNT_ARGS(__VA_ARGS__)) (__VA_ARGS__)
#define _OVR(macroName, number_of_args)   _OVR_EXPAND(macroName, number_of_args)
#define _OVR_EXPAND(macroName, number_of_args)    macroName##number_of_args

#define _COUNT_ARGS(...)  _ARG_PATTERN_MATCH(__VA_ARGS__, 9,8,7,6,5,4,3,2,1)
#define _ARG_PATTERN_MATCH(_1,_2,_3,_4,_5,_6,_7,_8,_9, N, ...)   N

#define rep(...) OVERLOADED_MACRO(rep, __VA_ARGS__)
#define repd(...) OVERLOADED_MACRO(repd, __VA_ARGS__)

#define rep3(i, a, b) for (int i = a; i < b; ++i)
#define rep2(i, n) rep3(i, 0, n)
#define repd3(i, a, b) for(int i = b - 1; i >= a; --i)
#define repd2(i, n) repd3(i, 0, n)

#define F first
#define S second

#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define all(v) v.begin(),v.end()

#define bitcount __builtin_popcountll
#define gcd __gcd
//for trailing 1s, do trailing0(n + 1)
#define leading0 __builtin_clzll
#define trailing0 __builtin_ctzll
#define isodd(n) (n & 1)
#define iseven(n) (!(n & 1))

#define sz(v) ((int) v.size())
#define del_rep(v) sort(all(v)); v.erase(unique(all(v)), v.end());
#define checkbit(n, b) ((n >> b) & 1)

#ifdef DEBUG
#define debug(args...) {\
    std::string _s = #args;\
    replace(_s.begin(), _s.end(), ',', ' ');\
    std::stringstream _ss(_s);\
    std::istream_iterator <std::string> _it(_ss);\
    err(_it, args);\
}

#define print_container(v) {\
    bool first = true; os << "[";\
    for (auto x : v) {\
        if (!first) os << ", "; os << x; first = false;\
    }\
    return os << "]";\
}

void err (std::istream_iterator <std::string> it) {}
template <typename T, typename... Args>
void err (std::istream_iterator <std::string> it, T a, Args... args) {
    std::cerr << *it << " = " << a << std::endl;
    err(++it, args...);
}
template <typename T1, typename T2>
inline std::ostream& operator << (std::ostream& os, const std::pair<T1, T2>& p) {
    return os << "(" << p.first << ", " << p.second << ")";
}
template<typename T>
inline std::ostream &operator << (std::ostream & os, const std::vector<T>& v) {
    print_container(v);
}
template<typename T>
inline std::ostream &operator << (std::ostream & os, const std::set<T>& v) {
    print_container(v);
}
template<typename T1, typename T2>
inline std::ostream &operator << (std::ostream & os, const std::map<T1, T2>& v) {
    print_container(v);
}
template<typename T1, typename T2, class C>
inline std::ostream &operator << (std::ostream & os, const unordered_map<T1, T2, C>& v) {
    print_container(v);
}
template<typename T, class C>
inline std::ostream &operator << (std::ostream & os, const unordered_set<T, C>& v) {
    print_container(v);
}
template<typename T1, typename T2>
inline std::ostream &operator << (std::ostream & os, const std::multimap<T1, T2>& v) {
    print_container(v);
}
template<typename T>
inline std::ostream &operator << (std::ostream & os, const std::multiset<T>& v) {
    print_container(v);
}
#else
#define debug(args...) 0
#endif

//order_of_key(k) - number of elements e such that func(e, k) returns true, where func is less or less_equal
//find_by_order(k) - kth element in the set counting from 0
//
typedef tree <int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
typedef tree <int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_multiset;

const int INF = 1e9;
const double EPS = 1e-9;
const double PI = acosl(-1);
const int mod = 1e9 + 7;
const int maxn = 5e5 + 5;
const int maxa = 1e6 + 5;
const int logmax = 25;

struct custom_hash {
    // http://xorshift.di.unimi.it/splitmix64.c
    static uint64_t splitmix64(uint64_t x) {
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }
    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

struct pair_hash {
    static uint64_t splitmix64(uint64_t x) {
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }
    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
    size_t operator()(pair<int, int> p) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(p.first * 31 + p.second + FIXED_RANDOM);
    }
};

vector<int> sort_cyclic_shifts(string const& s) {
    int n = s.size();
    const int alphabet = 128;
    vector<int> p(n), c(n), cnt(max(alphabet, n), 0);
    //base case : length = 1, so sort by counting sort
    for (int i = 0; i < n; i++) cnt[s[i]]++;
    for (int i = 1; i < alphabet; i++) cnt[i] += cnt[i - 1];
    for (int i = 0; i < n; i++) p[--cnt[s[i]]] = i;
    c[p[0]] = 0;
    int classes = 1;
    for (int i = 1; i < n; i++) {
        if (s[p[i]] != s[p[i - 1]]) ++classes;
        c[p[i]] = classes - 1;
    }
    //inductive case, sort by radix sort on pairs (in fact you only need to sort by first elements now)
    vector<int> p_new(n), c_new(n);
    for (int h = 0; (1 << h) < n; ++h) {
        for (int i = 0; i < n; i++) {
            p_new[i] = p[i] - (1 << h);
            if (p_new[i] < 0) p_new[i] += n;
        }
        fill(cnt.begin(), cnt.begin() + classes, 0);
        for (int i = 0; i < n; i++) cnt[c[p_new[i]]]++;
        for (int i = 1; i < classes; i++) cnt[i] += cnt[i - 1];
        for (int i = n - 1; i >= 0; i--) p[--cnt[c[p_new[i]]]] = p_new[i];
        c_new[p[0]] = 0;
        classes = 1;
        for (int i = 1; i < n; i++) {
            pair<int, int> cur = {c[p[i]], c[(p[i] + (1 << h)) % n]};
            pair<int, int> prev = {c[p[i - 1]], c[(p[i - 1] + (1 << h)) % n]};
            if (cur != prev) ++classes;
            c_new[p[i]] = classes - 1;
        }
        c.swap(c_new);
    }
    return p;
}
vector<int> suffix_array_construct (string s) {
    s += "$";
    //what about s += " "; ?
    vector<int> sorted_shifts = sort_cyclic_shifts(s);
    //sorted_shifts.erase(sorted_shifts.begin());
    return sorted_shifts;
}

vvi g;
vi cnt[5], siz;
int ans = 0, n, k;

void dfs(int u, int p, int d) {
    cnt[d % k][u] = siz[u] = 1;
    for (auto v : g[u]) {
        if(v == p) continue;
        dfs(v, u, d + 1);
        rep(i, k) rep(j, k) {
            int rem = ((i + j - 2 * d) % k + k) % k;
            int extra = (k - rem) % k;
            ans += extra * cnt[i][u] * cnt[j][v];
        }
        rep(i, k) {
            cnt[i][u] += cnt[i][v];
        }
        siz[u] += siz[v];
    }
    ans += siz[u] * (n - siz[u]);
}

void solve() {
    cin >> n >> k;
    g.resize(n);
    siz.resize(n);
    rep(i, 5) cnt[i].resize(n);
    rep(i, n - 1) {
        int u, v;
        cin >> u >> v;
        --u, --v;
        g[u].pb(v);
        g[v].pb(u);
    }
    dfs(1, -1, 0);
    cout << ans / k << endl;
}

signed main(){
    fastio;
    cout << setprecision(6) << fixed;
    int t = 1;
    //cin >> t;
    while(t--){
        solve();
    }
    return 0;
}


#include <bits/stdc++.h>
#define pb push_back
using namespace std;

typedef long long ll;
const int N = 200000;
vector<int> tree[N];
int n, k;

int parent[N];
void dfs1(int node){
       for(auto i : tree[node])
              if(parent[i]==0){
                     parent[i] = node;
                     dfs1(i);
              }
}

ll Ps[N];
ll cnt[N][5];
void dfs2(int node){
       for(auto i : tree[node])
              if(parent[i]==node){
                     dfs2(i);
                     Ps[node] += Ps[i] + cnt[i][0];
                     for(int j = 0; j < k; j++)
                            cnt[node][j] += cnt[i][(j+k-1)%k];
              }
       cnt[node][0]++;
}

ll Pd[N];
ll ST[N][5];
ll ans;
void dfs3(int node){
       if(node == 1){
              ST[node][0]++;
              for(auto i : tree[node])
                     dfs3(i);
              return;
       }
       Pd[node] = Pd[parent[node]] + ST[parent[node]][0];
       ans += Pd[node];
       for(int i = 0; i < k; i++)
              ST[node][i] += ST[parent[node]][(i+k-1)%k];
       for(int i = 0; i < k; i++)
              ST[parent[node]][i] += cnt[node][(i+k-1)%k];
       Pd[parent[node]] += Ps[node] + cnt[node][0];
       ST[node][0]++;
       for(auto i : tree[node])
              if(parent[i]==node)
                     dfs3(i);
}

void solve(){
       cin >> n >> k;
       int a, b;
       for(int i = 0; i < n-1; i++){
              cin >> a >> b;
              tree[a].pb(b);
              tree[b].pb(a);
       }
       parent[1] = 1;
       dfs1(1);
       dfs2(1);
       ans = 0;
       dfs3(1);
       cout << ans;
}

int main(){
       ios::sync_with_stdio(false);

       solve();

       return 0;
}