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11 12
6 5 8 7 2 1 4 3 14 13 16 15 10 9 12 11
7 8 5 6 3 4 1 2 15 16 13 14 11 12 9 10
8 7 6 5 4 3 2 1 16 15 14 13 12 11 10 9
9 10 11 12 13 14 15 16 1 2 3 4 5 6 7 8
10 9 12 11 14 13 16 15 2 1 4 3 6 5 8 7
11 12 9 10 15 16 13 14 3 4 1 2 7 8 5 6
12 11 10 9 16 15 14 13 4 3 2 1 8 7 6 5
13 14 15 16 9 10 11 12 5 6 7 8 1 2 3 4
14 13 16 15 10 9 12 11 6 5 8 7 2 1 4 3
15 16 13 14 11 12 9 10 7 8 5 6 3 4 1 2
16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1
[R16Mul]
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4
1 1 1 1 2 2 2 2 3 3 3 3 4 4 4 4
1 2 3 4 2 1 4 3 3 4 1 2 4 3 2 1
1 5 9 13 1 5 9 13 1 5 9 13 1 5 9 13
1 6 11 16 1 6 11 16 1 6 11 16 1 6 11 16
1 5 9 13 2 6 10 14 3 7 11 15 4 8 12 16
1 6 11 16 2 5 12 15 3 8 9 14 4 7 10 13
1 1 1 1 5 5 5 5 9 9 9 9 13 13 13 13
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
1 1 1 1 6 6 6 6 11 11 11 11 16 16 16 16
1 2 3 4 6 5 8 7 11 12 9 10 16 15 14 13
1 5 9 13 5 1 13 9 9 13 1 5 13 9 5 1
1 6 11 16 5 2 15 12 9 14 3 8 13 10 7 4
1 5 9 13 6 2 14 10 11 15 3 7 16 12 8 4
1 6 11 16 6 1 16 11 11 16 1 6 16 11 6 1
R16_386:
[R16Add]
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
2 1 4 3 6 5 8 7 10 9 12 11 14 13 16 15
3 4 1 2 7 8 5 6 11 12 9 10 15 16 13 14
4 3 2 1 8 7 6 5 12 11 10 9 16 15 14 13
5 6 7 8 1 2 3 4 13 14 15 16 9 10 11 12
6 5 8 7 2 1 4 3 14 13 16 15 10 9 12 11
7 8 5 6 3 4 1 2 15 16 13 14 11 12 9 10
8 7 6 5 4 3 2 1 16 15 14 13 12 11 10 9
9 10 11 12 13 14 15 16 1 2 3 4 5 6 7 8
10 9 12 11 14 13 16 15 2 1 4 3 6 5 8 7
11 12 9 10 15 16 13 14 3 4 1 2 7 8 5 6
12 11 10 9 16 15 14 13 4 3 2 1 8 7 6 5
13 14 15 16 9 10 11 12 5 6 7 8 1 2 3 4
14 13 16 15 10 9 12 11 6 5 8 7 2 1 4 3
15 16 13 14 11 12 9 10 7 8 5 6 3 4 1 2
16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1
[R16Mul]
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2
1 1 3 3 1 1 3 3 1 1 3 3 1 1 3 3
1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4
1 1 1 1 5 5 5 5 1 1 1 1 5 5 5 5
1 2 1 2 5 6 5 6 1 2 1 2 5 6 5 6
1 1 3 3 5 5 7 7 1 1 3 3 5 5 7 7
1 2 3 4 5 6 7 8 1 2 3 4 5 6 7 8
1 1 1 1 1 1 1 1 9 9 9 9 9 9 9 9
1 2 1 2 1 2 1 2 9 10 9 10 9 10 9 10
1 1 3 3 1 1 3 3 9 9 11 11 9 9 11 11
1 2 3 4 1 2 3 4 9 10 11 12 9 10 11 12
1 1 1 1 5 5 5 5 9 9 9 9 13 13 13 13
1 2 1 2 5 6 5 6 9 10 9 10 13 14 13 14
1 1 3 3 5 5 7 7 9 9 11 11 13 13 15 15
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
abstract class IRing {
// 抽象方法
public abstract void printTable();
public abstract int add(int a,int b);
public abstract int mul(int a,int b);
public abstract int size();
// 静态方法
public static void printRing(IRing r){
int n=r.size();
System.out.printf("[R%dAdd]\n",n);
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
int ij=r.add(i,j);
System.out.printf("%d ",ij+1);
}
System.out.printf("\n");
}
System.out.printf("[R%dMul]\n",n);
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
int ij=r.mul(i,j);
System.out.printf("%d ",ij+1);
}
System.out.printf("\n");
}
}
}
class E8{
public int[] m_bVal;
public static E8 create(int idx)
{
int b1=((idx>>2)& 1);
int b2=((idx>>1)& 1);
int b3=((idx>>0)& 1);
return new E8(b1,b2,b3);
}
public E8(int b1,int b2,int b3)
{
m_bVal=new int[]{b1,b2,b3};
}
public int Idx()
{
int idx=m_bVal[0]*4+m_bVal[1]*2+m_bVal[2];
return idx;
}
public static boolean IsEqual(E8 a, E8 b)
{
return (b.m_bVal[0]==a.m_bVal[0] && b.m_bVal[1]==a.m_bVal[1] && b.m_bVal[2]==a.m_bVal[2]);
}
public static E8 Add(E8 a,E8 b)
{
E8 ret=new E8(a.m_bVal[0]^b.m_bVal[0],a.m_bVal[1]^b.m_bVal[1],a.m_bVal[2]^b.m_bVal[2]);
return ret;
}
public static E8 InvAdd(E8 a)
{
E8 ret=new E8((2-a.m_bVal[0])%2,(2-a.m_bVal[1])%2,(2-a.m_bVal[2])%2);
return ret;
}
public static E8 Mul(int ID,E8 a,E8 b)
{
if(ID==25){
E8 ret=new E8(0,0,0);
return ret;
}else if(ID==50){
E8 ret=new E8(a.m_bVal[0]*b.m_bVal[0],a.m_bVal[1]*b.m_bVal[1],a.m_bVal[2]*b.m_bVal[2]);
return ret;
}else{
return Mul(25,a,b);
}
}
}
public class R8 extends IRing {
// 实现抽象基类的方法
public void printTable(){
System.out.printf("R%d_%d:\n",size(),m_ID);
printRing(this);
}
public int add(int a,int b){
int c=m_add[a][b];
return c;
}
public int mul(int a,int b){
int c=m_mul[a][b];
return c;
}
public int size(){
return m_add.length;
}
public int m_ID;// 不同的编号代表不同的乘法
int[][] m_add;
int[][] m_mul;
public void initF8(){
m_ID=52;
m_add=new int[][]{
{0,1,2,3,4,5,6,7},
{1,0,4,7,2,6,5,3},
{2,4,0,5,1,3,7,6},
{3,7,5,0,6,2,4,1},
{4,2,1,6,0,7,3,5},
{5,6,3,2,7,0,1,4},
{6,5,7,4,3,1,0,2},
{7,3,6,1,5,4,2,0}
};
m_mul=new int[][]{
{0,0,0,0,0,0,0,0},
{0,1,2,3,4,5,6,7},
{0,2,3,4,5,6,7,1},
{0,3,4,5,6,7,1,2},
{0,4,5,6,7,1,2,3},
{0,5,6,7,1,2,3,4},
{0,6,7,1,2,3,4,5},
{0,7,1,2,3,4,5,6}
};
}
public void initE8(int ID){
m_ID=ID;
m_add=new int[8][8];
m_mul=new int[8][8];
E8[] Set=new E8[8];
for(int i=0;i<8;i++)
Set[i]=E8.create(i);
for(int i=0;i<8;i++)
for(int j=0;j<8;j++)
{
E8 IJ=E8.Add(Set[i],Set[j]);
int ij=IJ.Idx();
m_add[i][j]=ij;
E8 IJ1=E8.Mul(ID,Set[i],Set[j]);
int ij1=IJ1.Idx();
m_mul[i][j]=ij1;
}
}
public static void main (String args[]) {
R8 r8_25=new R8();
r8_25.initE8(25);
r8_25.printTable();
R8 r8_50=new R8();
r8_50.initE8(50);
r8_50.printTable();
R8 r8_52=new R8();
r8_52.initF8();
r8_52.printTable();
}
}
class M2{
public int m_a11,m_a12,m_a21,m_a22;
public M2(int a11,int a12,int a21,int a22){
m_a11=a11;
m_a12=a12;
m_a21=a21;
m_a22=a22;
}
public static M2 create16(int idx)
{
int b1=((idx>>3)& 1);
int b2=((idx>>2)& 1);
int b3=((idx>>1)& 1);
int b4=((idx>>0)& 1);
return new M2(b1,b2,b3,b4);
}
public int Idx16()
{
int idx=m_a11*8+m_a12*4+m_a21*2+m_a22;
return idx;
}
public boolean isEqual(M2 m)
{
return (m_a11==m.m_a11 && m_a12==m.m_a12 && m_a21==m.m_a21 && m_a22==m.m_a22);
}
public M2 Add(M2 m){
return new M2( m_a11+m.m_a11,m.m_a12+m_a12,m_a21+m.m_a21,m_a22+m.m_a22);
}
public M2 Mul(int ID,M2 m){
if(ID==300){
return new M2( m_a11 * m.m_a11+m_a12 * m.m_a21,m_a11 * m.m_a12+m_a12 * m.m_a22, m_a21 * m.m_a11+m_a22 * m.m_a21, m_a21 * m.m_a12+m_a22 * m.m_a22);
//return new M2( m_a11 * m.m_a21+m_a12 * m.m_a11,m_a11 * m.m_a22+m_a12 * m.m_a12, m_a21 * m.m_a21+m_a22 * m.m_a11, m_a21 * m.m_a22+m_a22 * m.m_a12);
}else if(ID==301){
return new M2(0,0,0,0);
}else if(ID==305){
return new M2( m_a11 * m.m_a11,0, 0, 0);
}else if(ID==307){
return new M2( m_a11 * m.m_a11,0, 0, m_a22 * m.m_a22);
}else if(ID==320){
return new M2( m_a11 * m.m_a11,m_a12 * m.m_a12, 0, m_a22 * m.m_a22);
}else if(ID==386){
return new M2( m_a11 * m.m_a11,m_a12 * m.m_a12, m_a21 *m.m_a21, m_a22 * m.m_a22);
//return new M2( m_a11 & m.m_a11,m_a12 & m.m_a12, m_a21 & m.m_a21, m_a22 & m.m_a22);
}else{
return new M2(0,0,0,0);
}
}
public M2 mod2(){
return new M2( m_a11%2,m_a12%2,m_a21%2,m_a22%2);
}
public int det(){
int ret=m_a11*m_a22-m_a12*m_a21;
return ret;
}
}
public class M2r extends IRing {
public int m_ID;// 不同的编号代表不同的乘法
int[][] m_add;
int[][] m_mul;
// 实现抽象基类的方法
public void printTable(){
System.out.printf("R%d_%d:\n",size(),m_ID);
printRing(this);
}
public int add(int a,int b){
int c=m_add[a][b];
return c;
}
public int mul(int a,int b){
int c=m_mul[a][b];
return c;
}
public int size(){
return m_add.length;
}
public void initR16(int ID){
m_ID=ID;
int n=16;
m_add=new int[n][n];
m_mul=new int[n][n];
M2[] Set=new M2[n];
for(int i=0;i<n;i++)
Set[i]=M2.create16(i);
for(int i=0;i<n;i++)
for(int j=0;j<n;j++)
{
M2 IJ=Set[i].Add(Set[j]).mod2();
int ij=IJ.Idx16();
m_add[i][j]=ij;
M2 IJ1=Set[i].Mul(ID,Set[j]).mod2();
int ij1=IJ1.Idx16();
m_mul[i][j]=ij1;
}
}
public static void main(String args[]){
M2r r16_300=new M2r();
r16_300.initR16(300);
r16_300.printTable();
M2r r16_386=new M2r();
r16_386.initR16(386);
r16_386.printTable();
}
}