Skip to content

Instantly share code, notes, and snippets.

@yao2030
Created November 2, 2012 02:30
Show Gist options
  • Save yao2030/3998332 to your computer and use it in GitHub Desktop.
Save yao2030/3998332 to your computer and use it in GitHub Desktop.
using java to implement binomial coefficient
public class Binomial
{
public static int[][] binomial(int N)
{
int[][] a = new int[N+1][N+1];
for (int i = 1; i <= N; i++)
for (int j = 1; j <= i; j++)
{
if (i == j)
a[i][j] = 1;
else
a[i][j] = a[i-1][j] + a[i-1][j-1];
}
return a;
}
public static boolean[][] isOdd(int[][] a)
{
int N = a.length;
boolean[][] b = new boolean[N][N];
for(int i = 1; i < N; i++)
for(int j = 1; j < N; j++)
if(a[i][j] == 0)
b[i][j] = false;
else if(a[i][j] % 2 == 0)
b[i][j] = true;
return b;
}
public static void main(String[] args)
{
int N = Integer.parseInt(args[0]);
int[][] b = binomial(N);
boolean[][] c = isOdd(b);
RelativePrime.show(c);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment