Cappuccino90

Untitled

Oct 13th, 2015
191
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.96 KB | None | 0 0
  1.  
  2. import java.math.BigInteger;
  3.  
  4. public class DUDU2 {
  5.  
  6.     public static void main(String[] args) {
  7.  
  8.         // type in here your number for n
  9.         int n = 5555;
  10.  
  11.         // this for loop is optional. it shows you every calculation from 5 to n
  12.         for (int i = 1188; i <= n; i++) {
  13.  
  14.             BigInteger[][][][] E = new BigInteger[2 * i][2 * i + 3][5][4];
  15.  
  16.             // fill BigInteger array with zeros to avoid NullPointerExceptions
  17.             for (int c = 0; c < E.length; c++) {
  18.                 for (int v = 0; v < E[0].length; v++) {
  19.                     for (int b = 0; b < E[0][0].length; b++) {
  20.                         for (int f = 0; f < E[0][0][0].length; f++) {
  21.                             E[c][v][b][f] = BigInteger.ZERO;
  22.                         }
  23.                     }
  24.                 }
  25.             }
  26.            
  27.             // first Up in the path is static, so we give it a 1
  28.             E[0][2][1][0] = BigInteger.ONE;
  29.  
  30.             // loops through the path and checks for specific ending patterns
  31.             for (int x = 1; x < 2 * i; x++) {
  32.                 for (int s = (x + 1) % 2; s < x + 2; s += 2) {
  33.                     for (int a = 0; a <= 2; a++) {
  34.                         E[x][s + 1][a + 1][0] = E[x - 1][s][a + 1][0].add(E[x - 1][s][a + 1][2]);
  35.                         E[x][s + 1][a + 1][1] = E[x - 1][s + 2][a + 1][0]
  36.                                 .add(E[x - 1][s + 2][a + 1][1].add(E[x - 1][s + 2][a + 1][3]));
  37.                         E[x][s + 1][a + 1][2] = E[x - 1][s][a][3].add(E[x - 1][s][a + 1][1]);
  38.                         E[x][s + 1][a + 1][3] = E[x - 1][s + 2][a + 1][2];
  39.                     }
  40.                 }
  41.             }
  42.  
  43.             BigInteger sum = BigInteger.ZERO;
  44.  
  45.             // sums up the results and prints them out
  46.             for (int x = 0; x < 4; x++) {
  47.                 sum = sum.add(E[2 * i - 1][1][3][x]);
  48.             }
  49.             System.out.println("n=" + i + ": " + sum);
  50.         }
  51.     }
  52. }
Advertisement
Comments
  • User was banned
Add Comment
Please, Sign In to add comment