Go: package main

import (
	"fmt"
	"math"
)

func main(){
	var n, m, k int
	for {
		fmt.Scan(&n, &m, &k)
		if n == 0 && m == 0 && k == 0{
			break
		}

		dp := make([][]int, n+1)
		for i:= 0; i < n+1; i++{
			dp[i] = make([]int, m*n + 1)
		}

		for i := 1; i <=m ; i++{
			dp[1][i] = 1
		}

		for i:= 1; i < n; i++{
			for j := 0; j <= i * m; j++{
				for k := 1; k <= m; k++{
					dp[i+1][j+k] += dp[i][j]
				}
			}
		}

		count := 0.0
		div := math.Pow(float64(m), float64(n))
		for i := 0; i <= n * m; i++{
			bill := 0.0
			if i <= k{
				bill = 1.0
			} else {
				bill = float64(i - k)
			}
			count += bill * float64(dp[n][i]) / div
		}
		fmt.Printf("%.010f\n", count)
	}
}

Python: import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 998244353

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    rr = []

    while True:
        n,m,k = LI()
        if n == 0:
            break
        r = [[0] * (n*m+1) for _ in range(n+1)]
        r[0][0] = 1
        for i in range(n):
            for j in range(i,n*m):
                if r[i][j] == 0:
                    break
                for kk in range(1,m+1):
                    r[i+1][j+kk] += r[i][j] / m
        t = 0
        for kk in range(n*m+1):
            c = max(kk-k,1)
            t += c * r[n][kk]
        rr.append('{:0.9f}'.format(t))

    return '\n'.join(map(str, rr))


print(main())

C++: #include <iostream>
#include <string>
#include <cctype>
#include <memory>
#include <vector>
#include <array>
#include <algorithm>
#include <iomanip>
#include <stack>

//auto in = freopen("input", "r", stdin);

using namespace std;

struct Value{
	Value(long long v, long long count=1) : count(count), v(v){};
	int count;
	long long v;
};

int main(){
	cout << setprecision(20);
	while(true){
		long long n, m, k, sum = 0;
		cin >> n >> m >> k;
		if(n==0 && m==0 && k==0) break;
		stack<Value> s;
		
		s.push(Value(0,0));

		while(!s.empty()){
			auto v = s.top(); s.pop();
			if(v.count==n){
				sum += v.v-k>0 ? v.v-k : 1;
				continue;
			}
			for(int i=1; i<=m; ++i){
				auto nv = v.v + i;
				s.push(Value(nv, v.count+1));
			}
		}
		cout << sum/std::powf((long double)m,n) << endl;
	}
}

C++: #include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
using namespace std;

int main(){
    while(1){
        int n,m,k;
        cin >> n >> m >> k;
        if(n == 0) break;

        vector<double> dp(n*m+1, 0);
        dp[0] = 1;
        for(int i=0; i<n; i++){
            vector<double> ndp(n*m+1, 0);
            for(int j=0; j<=i*m; j++){
                for(int d=1; d<=m; d++){
                    ndp[j+d] += dp[j]/m;
                }
            }
            dp = ndp;
        }
        double ans = 0;
        for(int i=0; i<=n*m; i++){
            int bill = max(1, i-k);
            ans += bill*dp[i];
        }
        cout << fixed << setprecision(10);
        cout << ans << endl;
    }
    return 0;
}

C++: #include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>

using namespace std;

#define FOR(i,k,n) for(int i=(k); i<(int)n; ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

template<class T> void debug(T begin, T end){ for(T i = begin; i != end; ++i) cout<<*i<<" "; cout<<endl; }

typedef long long ll;
const int INF = 100000000;
const double EPS = 1e-8;
const int MOD = 1000000007;
ll dfs(int n, int m, int k){
  if(n == 0) return max(1, k);
  ll res = 0;
  for(int i = 1; i <= m; i++){
    res += dfs(n-1, m, k + i);
  }
  return res;
}
int main(){
  int n,m,k;
  while(cin>>n>>m>>k && n){
    ll sum = dfs(n, m, -k);
    double ans = (double)sum/pow((double)m, (double)n);
    printf("%.8lf\n",ans);
  }
  return 0;
}

C++: #include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>

using namespace std;

int ret;
int n, m, k;

void dfs(int freq, int num)
{
	if (freq == 0){
		ret += ((num - k) <= 0 ? 1 : num - k);
		// printf("%d %d -> %d\n", freq, num, ret);
		return;
	}
	else {
		for (int i = 1; i <= m; i++){
			dfs(freq-1, num + i);
		}
	}
	return;
}

int main(void)
{
	while (cin >> n >> m >> k, n && m){
		ret = 0;
		dfs(n, 0);

		printf("%.08lf\n", ret / pow((double)m, (double)n));
	}
}

C++: #include <iostream>
#include <math.h>
using namespace std;
double res,k,n;

void check(double a,double m,double x){
	if(a == 0){
		if(x-k < 1){
			x = 1;
			res += (1/pow(m,n)) * x;
		}
		else res += (1/pow(m,n)) * (x-k);
	}
	else{
		for(int i = 1;i <= m;i++){
			check(a-1,m,x+i);
		}
	}
}

int main(){
	double m;
	while(1){
		res = 0;
		cin >> n >> m >> k;
		if(n == 0)break;
		check(n,m,0);
		printf("%.10f\n",res);
	}
	return 0;
}

C++: #include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define o(a) cout << a << endl
// #define int long long
#define first fi
#define second se
using namespace std;
typedef pair<int, int> P;

int d[30][300010];

signed main(){
    int n, m, k;
    while(1){
        cin >> n >> m >> k;
        if(n + m + k == 0) break;
        rep(i, 0, 30) rep(j, 0, 300010) d[i][j] = 0;
        d[0][0] = 1;
        rep(i, 0, n){
            rep(j, i, 300000){
                if(d[i][j] == 0) break;                
                rep(l, 1, m + 1){
                    d[i + 1][j + l] += d[i][j];
                }
            }
        }
        double sum = 0;
        rep(i, 0, 300000){
            if(i <= k) sum += d[n][i];
            else sum += d[n][i] * (i - k);
        }
        rep(i, 0, n) sum /= (double)m;
        printf("%.14lf\n", sum);
    }
}

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

#define rep(i, n) for(int i = 0; i < (n); i++)
#define repp(i, l, r) for(int i = (l); i < (r); i++)
#define per(i, n) for(int i = ((n)-1); i >= 0; i--)
#define perr(i, l, r) for(int i = ((r)-1); i >= (l); i--)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007
#define IINF 1000000000
#define LINF 1000000000000000000
#define SP <<" "<<
#define CYES cout<<"Yes"<<endl
#define CNO cout<<"No"<<endl
#define CFS cin.tie(0);ios::sync_with_stdio(false)

typedef long long LL;
typedef long double LD;

int main(){
  while(1){
    double n,m,k;
    cin >> n >> m >> k;
    if(n==0) return 0;
    vector<int> v(n,1);
    double tmp=n;
    double sum=0;
    while(1){
      sum+=max(tmp-k,1.0);
      rep(i,n){
        if(v[i]<m){
          v[i]++;
          tmp++;
          goto next;
        }else{
          v[i]=1;
          tmp-=m-1;
        }
      }
      break;
      next:;
    }
    rep(i,n) sum/=m;
    cout << fixed << setprecision(10) << sum << endl;
  }
  return 0;
}