Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.*;
- import java.math.*;
- /*
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
- */
- /**
- *
- * @author alumno
- */
- public class CombinationsB {
- public static BigInteger fact(long n) {
- BigInteger end = new BigInteger("1"); //because n*(n-1)*(n-2)*...3*2*1=n!, btw is my acumulator
- for (long i = 1; i <= n; i++) {
- end = end.multiply(BigInteger.valueOf(i));
- }
- return end;
- }
- public static BigInteger combinations(long n, long k) {
- return fact(n).divide(fact(k).multiply(fact(n - k)));
- }
- public static BigInteger distributions(long n, long k) {
- return combinations(n + k - 1, k - 1);
- }
- public static void main(String[] args) throws IOException {
- long k1 = 19, k2 = 64;
- // System.out.println(""+distributions(500,150));
- for (int q = 1; q < 1000; q++) {
- if (distributions(q - k1, k1).compareTo(distributions(q - k2, k2))==0) {
- System.out.println(":" + q);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement