public static int fac(int k) {
        if (k < 0)
            return 0;
        int kfac = 1;
        while (k > 1) {
            kfac = kfac * k;
            k = k - 1;
        }
        return kfac;
    }