Created
May 5, 2017 13:05
-
-
Save Keridos/b755d1b48169a2ee67afef3cac707fac to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.company; | |
public class Main { | |
public static void main(String[] args) { | |
System.out.println(" 6 fakultät : " + (long) (double) fakultaet(49L) / fakultaet(43L)); | |
System.out.println(" 6 über 49 : " + binomialKoeffizient(49L, 6L)); | |
System.out.println(" 6 über 49 Lottolösung : " + modLottoProblemLoesung(49, 6)); | |
} | |
public static long fakultaet(long n) { | |
return n > 1 ? n * fakultaet(--n) : n == 1 ? 1 : 0; | |
} | |
public static long binomialKoeffizient(long n, long k) { | |
return (((0 <= n) && n <= k) || (n < 0) || (k < 0)) ? 0 : (fakultaet(n) / (fakultaet(n - k) * fakultaet(k))); | |
} | |
public static long modLottoProblemLoesung(long n, long k) { | |
return binomialKoeffizient(n, k) * fakultaet(k); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment