/*****************************************************************************/
/*									     */
/*  FACTOR A, B, A-B, AND A+B						     */
/*  11/25/06 (dkc)							     */
/*									     */
/*  Input to this program is a pair of (a,b) values ((a1,b1) and (a2,b2)).   */
/*  A third (a,b) value is generated from (b1,b2).  These (a,b) values	     */
/*  correspond to different representations of T**p.  a, b, a-b, and a+b     */
/*  are factored for each (a,b) value.					     */
/*									     */
/*  Note: a-b and a+b are switched for [(a**p-b**p)/(a-b)] (the third (a,b)  */
/*  value).								     */
/*									     */
/*****************************************************************************/
#include <stdio.h>
#include <math.h>
#include "table10.h"
int main ()
{
int insize=43;
unsigned int input[4*43]={
     0x2394,     0x141d,      0x18d, 0, 
     0x2394,      0xf77,      0x18d, 0, 
     0x1fa5,     0x1c79,      0x10f, 0, 
     0x1fa5,      0x32c,      0x10f, 1, 
     0x1e4d,     0x1b12,      0x17b, 0, 
     0x1e4d,      0x33b,      0x17b, 0, 
     0x1693,     0x12fd,      0x133, 0, 
     0x1693,      0x396,      0x133, 0, 
     0x1474,     0x1115,       0xc7, 1, 
     0x1474,      0x35f,       0xc7, 1, 
     0x140a,      0xb9b,      0x10f, 0, 
     0x140a,      0x86f,      0x10f, 0, 
     0x125b,      0xd82,       0xb5, 1, 
     0x125b,      0x4d9,       0xb5, 0, 
      0xec3,      0xd48,       0xa3, 1, 
      0xec3,      0x17b,       0xa3, 0, 
      0xc83,      0x7f1,       0xc7, 0, 
      0xc83,      0x492,       0xc7, 0, 
      0xa9f,      0x7bc,       0xb5, 0, 
      0xa9f,      0x2e3,       0xb5, 0, 
      0xa57,      0x8db,       0x7f, 0, 
      0xa57,      0x17c,       0x7f, 1, 
      0x959,      0x56a,       0xa3, 0, 
      0x959,      0x3ef,       0xa3, 0, 
      0x8a5,      0x61f,       0x6d, 0, 
      0x8a5,      0x286,       0x6d, 1, 
      0x666,      0x3f1,       0x7f, 0, 
      0x666,      0x275,       0x7f, 0, 
      0x4ec,      0x3b9,       0x6d, 0, 
      0x4ec,      0x133,       0x6d, 0, 
      0x4a6,      0x397,       0x49, 1, 
      0x4a6,      0x10f,       0x49, 1, 
      0x2bf,      0x1e7,       0x49, 0, 
      0x2bf,       0xd8,       0x49, 0, 
      0x1b1,      0x143,       0x25, 0, 
      0x1b1,       0x6e,       0x25, 1, 
       0xfc,       0xb5,       0x25, 0, 
       0xfc,       0x47,       0x25, 0, 
       0xa3,       0x6b,       0x13, 0, 
       0xa3,       0x38,       0x13, 1, 
       0x5a,       0x49,       0x13, 0, 
       0x5a,       0x11,       0x13, 0, 
	0x2,	    0x1,       0x13, 1};

int tsize=551; // prime look-up table size
int h,i,j,k,m;
int a,b,c,d;
int save[100];
FILE *Outfp;
Outfp = fopen("out28c.dat","w");
/*******************/
/*  factor input   */
/*******************/
for (h=0; h<insize; h+=2) {
/******************/
/*  first pair	  */
/******************/
   a=input[4*h];
   b=input[4*h+1];
   c=a+b;
   d=a-b;
   fprintf(Outfp,"%#4x %d %#8x %#08x ",input[4*h+2],input[4*h+3],a,b);
   m=0;
   for (i=0; i<tsize; i++) {
      j=table[i];
      if (j*j>a)
	 break;
      if ((a/j)*j!=a)
	 continue;
      for (k=0; k<100; k++) {
	 save[m]=j;
	 m=m+1;
	 a=a/j;
	 if ((a/j)*j!=a)
	    break;
	 }
      }
   if (a!=1) {
      save[m]=a;
      m=m+1;
      }
   if (m==1)
      fprintf(Outfp,"%d",save[0]);
   else {
      for (i=0; i<m-1; i++) {
	 fprintf(Outfp,"%d*",save[i]);
	 }
      fprintf(Outfp,"%d",save[m-1]);
      }
   fprintf(Outfp,"  ");
   if (b==1)
      fprintf(Outfp,"%d",b);
   else {
      m=0;
      for (i=0; i<tsize; i++) {
	 j=table[i];
	 if (j*j>b)
	    break;
	 if ((b/j)*j!=b)
	    continue;
	 for (k=0; k<100; k++) {
	    save[m]=j;
	    m=m+1;
	    b=b/j;
	    if ((b/j)*j!=b)
	       break;
	    }
	 }
      if (b!=1) {
	 save[m]=b;
	 m=m+1;
	 }
      if (m==1)
	 fprintf(Outfp,"%d",save[0]);
      else {
	 for (i=0; i<m-1; i++) {
	    fprintf(Outfp,"%d*",save[i]);
	    }
	 fprintf(Outfp,"%d",save[m-1]);
	 }
      }
   fprintf(Outfp,"  ");
   m=0;
   for (i=0; i<tsize; i++) {
      j=table[i];
      if (j*j>c)
	 break;
      if ((c/j)*j!=c)
	 continue;
      for (k=0; k<100; k++) {
	 save[m]=j;
	 m=m+1;
	 c=c/j;
	 if ((c/j)*j!=c)
	    break;
	 }
      }
   if (c!=1) {
      save[m]=c;
      m=m+1;
      }
   if (m==1)
      fprintf(Outfp,"%d",save[0]);
   else {
      for (i=0; i<m-1; i++) {
	 fprintf(Outfp,"%d*",save[i]);
	 }
      fprintf(Outfp,"%d",save[m-1]);
      }
   fprintf(Outfp,"  ");
   if (d==1)
      fprintf(Outfp,"%d",d);
   else {
      m=0;
      for (i=0; i<tsize; i++) {
	 j=table[i];
	 if (j*j>d)
	    break;
	 if ((d/j)*j!=d)
	    continue;
	 for (k=0; k<100; k++) {
	    save[m]=j;
	    m=m+1;
	    d=d/j;
	    if ((d/j)*j!=d)
	       break;
	    }
	 }
      if (d!=1) {
	 save[m]=d;
	 m=m+1;
	 }
      if (m==1)
	 fprintf(Outfp,"%d",save[0]);
      else {
	 for (i=0; i<m-1; i++) {
	    fprintf(Outfp,"%d*",save[i]);
	    }
	 fprintf(Outfp,"%d",save[m-1]);
	 }
      }
   fprintf(Outfp,"\n");
/******************/
/*  second pair   */
/******************/
   a=input[4*h];
   b=a-input[4*h+1];
   if (a<b) {
      c=a;
      a=b;
      b=c;
      }
   c=a+b;
   d=a-b;
   fprintf(Outfp," %#8x %#8x  ",a,b);
   m=0;
   for (i=0; i<tsize; i++) {
      j=table[i];
      if (j*j>a)
	 break;
      if ((a/j)*j!=a)
	 continue;
      for (k=0; k<100; k++) {
	 save[m]=j;
	 m=m+1;
	 a=a/j;
	 if ((a/j)*j!=a)
	    break;
	 }
      }
   if (a!=1) {
      save[m]=a;
      m=m+1;
      }
   if (m==1)
      fprintf(Outfp,"%d",save[0]);
   else {
      for (i=0; i<m-1; i++) {
	 fprintf(Outfp,"%d*",save[i]);
	 }
      fprintf(Outfp,"%d",save[m-1]);
      }
   fprintf(Outfp,"  ");
   if (b==1)
      fprintf(Outfp,"%d",b);
   else {
      m=0;
      for (i=0; i<tsize; i++) {
	 j=table[i];
	 if (j*j>b)
	    break;
	 if ((b/j)*j!=b)
	    continue;
	 for (k=0; k<100; k++) {
	    save[m]=j;
	    m=m+1;
	    b=b/j;
	    if ((b/j)*j!=b)
	       break;
	    }
	 }
      if (b!=1) {
	 save[m]=b;
	 m=m+1;
	 }
      if (m==1)
	 fprintf(Outfp,"%d",save[0]);
      else {
	 for (i=0; i<m-1; i++) {
	    fprintf(Outfp,"%d*",save[i]);
	    }
	 fprintf(Outfp,"%d",save[m-1]);
	 }
      }
   fprintf(Outfp,"  ");
   m=0;
   for (i=0; i<tsize; i++) {
      j=table[i];
      if (j*j>c)
	 break;
      if ((c/j)*j!=c)
	 continue;
      for (k=0; k<100; k++) {
	 save[m]=j;
	 m=m+1;
	 c=c/j;
	 if ((c/j)*j!=c)
	    break;
	 }
      }
   if (c!=1) {
      save[m]=c;
      m=m+1;
      }
   if (m==1)
      fprintf(Outfp,"%d",save[0]);
   else {
      for (i=0; i<m-1; i++) {
	 fprintf(Outfp,"%d*",save[i]);
	 }
      fprintf(Outfp,"%d",save[m-1]);
      }
   fprintf(Outfp,"  ");
   if (d==1)
      fprintf(Outfp,"%d",d);
   else {
      m=0;
      for (i=0; i<tsize; i++) {
	 j=table[i];
	 if (j*j>d)
	    break;
	 if ((d/j)*j!=d)
	    continue;
	 for (k=0; k<100; k++) {
	    save[m]=j;
	    m=m+1;
	    d=d/j;
	    if ((d/j)*j!=d)
	       break;
	    }
	 }
      if (d!=1) {
	 save[m]=d;
	 m=m+1;
	 }
      if (m==1)
	 fprintf(Outfp,"%d",save[0]);
      else {
	 for (i=0; i<m-1; i++) {
	    fprintf(Outfp,"%d*",save[i]);
	    }
	 fprintf(Outfp,"%d",save[m-1]);
	 }
      }
   fprintf(Outfp,"\n");
/******************/
/*  third pair	  */
/******************/
   b=input[4*h+1];
   a=input[4*h]-b;
   if (a<b) {
      c=a;
      a=b;
      b=c;
      }
   c=a-b;	       // switch a-b and a+b
   d=a+b;	       //
   fprintf(Outfp," %#8x %#8x  ",a,b);
   m=0;
   for (i=0; i<tsize; i++) {
      j=table[i];
      if (j*j>a)
	 break;
      if ((a/j)*j!=a)
	 continue;
      for (k=0; k<100; k++) {
	 save[m]=j;
	 m=m+1;
	 a=a/j;
	 if ((a/j)*j!=a)
	    break;
	 }
      }
   if (a!=1) {
      save[m]=a;
      m=m+1;
      }
   if (m==1)
      fprintf(Outfp,"%d",save[0]);
   else {
      for (i=0; i<m-1; i++) {
	 fprintf(Outfp,"%d*",save[i]);
	 }
      fprintf(Outfp,"%d",save[m-1]);
      }
   fprintf(Outfp,"  ");
   if (b==1)
      fprintf(Outfp,"%d",b);
   else {
      m=0;
      for (i=0; i<tsize; i++) {
	 j=table[i];
	 if (j*j>b)
	    break;
	 if ((b/j)*j!=b)
	    continue;
	 for (k=0; k<100; k++) {
	    save[m]=j;
	    m=m+1;
	    b=b/j;
	    if ((b/j)*j!=b)
	       break;
	    }
	 }
      if (b!=1) {
	 save[m]=b;
	 m=m+1;
	 }
      if (m==1)
	 fprintf(Outfp,"%d",save[0]);
      else {
	 for (i=0; i<m-1; i++) {
	    fprintf(Outfp,"%d*",save[i]);
	    }
	 fprintf(Outfp,"%d",save[m-1]);
	 }
      }
   fprintf(Outfp,"  ");
   m=0;
   for (i=0; i<tsize; i++) {
      j=table[i];
      if (j*j>c)
	 break;
      if ((c/j)*j!=c)
	 continue;
      for (k=0; k<100; k++) {
	 save[m]=j;
	 m=m+1;
	 c=c/j;
	 if ((c/j)*j!=c)
	    break;
	 }
      }
   if (c!=1) {
      save[m]=c;
      m=m+1;
      }
   if (m==1)
      fprintf(Outfp,"%d",save[0]);
   else {
      for (i=0; i<m-1; i++) {
	 fprintf(Outfp,"%d*",save[i]);
	 }
      fprintf(Outfp,"%d",save[m-1]);
      }
   fprintf(Outfp,"  ");
   if (d==1)
      fprintf(Outfp,"%d",d);
   else {
      m=0;
      for (i=0; i<tsize; i++) {
	 j=table[i];
	 if (j*j>d)
	    break;
	 if ((d/j)*j!=d)
	    continue;
	 for (k=0; k<100; k++) {
	    save[m]=j;
	    m=m+1;
	    d=d/j;
	    if ((d/j)*j!=d)
	       break;
	    }
	 }
      if (d!=1) {
	 save[m]=d;
	 m=m+1;
	 }
      if (m==1)
	 fprintf(Outfp,"%d",save[0]);
      else {
	 for (i=0; i<m-1; i++) {
	    fprintf(Outfp,"%d*",save[i]);
	    }
	 fprintf(Outfp,"%d",save[m-1]);
	 }
      }
   fprintf(Outfp,"\n");
   fprintf(Outfp,"\n");
   }
fprintf(Outfp,"\n");
fclose(Outfp);
return(0);
}