Advertisement
ArCiGo

Solución de Ecuaciones

Apr 13th, 2013
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.10 KB | None | 0 0
  1.  
  2. import java.io.*;
  3. import java.math.*;
  4. /*
  5.  * To change this template, choose Tools | Templates
  6.  * and open the template in the editor.
  7.  */
  8.  
  9. /**
  10.  *
  11.  * @author alumno
  12.  */
  13. public class CombinationsB {
  14.  
  15.     public static BigInteger fact(long n) {
  16.         BigInteger end = new BigInteger("1");      //because n*(n-1)*(n-2)*...3*2*1=n!, btw is my acumulator
  17.         for (long i = 1; i <= n; i++) {
  18.             end = end.multiply(BigInteger.valueOf(i));
  19.         }
  20.         return end;
  21.     }
  22.  
  23.     public static BigInteger combinations(long n, long k) {
  24.         return fact(n).divide(fact(k).multiply(fact(n - k)));
  25.     }
  26.  
  27.     public static BigInteger distributions(long n, long k) {
  28.         return combinations(n + k - 1, k - 1);
  29.     }
  30.  
  31.     public static void main(String[] args) throws IOException {
  32.  
  33.         long k1 = 19, k2 = 64;
  34. //        System.out.println(""+distributions(500,150));
  35.         for (int q = 1; q < 1000; q++) {
  36.             if (distributions(q - k1, k1).compareTo(distributions(q - k2, k2))==0) {
  37.                 System.out.println(":" + q);
  38.             }
  39.         }
  40.     }
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement