/*****************************************************************************/
/*									     */
/*  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=91;
unsigned int input[91*2]={
     0x12b4,     0x1139, 
     0x12b4,      0x17b, 
     0x125b,      0xd82, 
     0x125b,      0x4d9, 
      0xfd1,      0xd01, 
      0xfd1,      0x2d0, 
      0xf0a,      0xa43, 
      0xf0a,      0x4c7, 
      0xec3,      0xd48, 
      0xec3,      0x17b, 
      0xeb3,      0xbf4, 
      0xeb3,      0x2bf, 
      0xe7d,      0x7a9, 
      0xe7d,      0x6d4, 
      0xd26,      0xcdd, 
      0xd26,       0x49, 
      0xd03,      0xa8d, 
      0xd03,      0x276, 
      0xc83,      0x7f1, 
      0xc83,      0x492, 
      0xbe3,      0xa10, 
      0xbe3,      0x1d3, 
      0xbd0,      0x827, 
      0xbd0,      0x3a9, 
      0xa9f,      0x7bc, 
      0xa9f,      0x2e3, 
      0xa57,      0x8db, 
      0xa57,      0x17c, 
      0x959,      0x56a, 
      0x959,      0x3ef, 
      0x8a5,      0x61f, 
      0x8a5,      0x286, 
      0x86f,      0x69b, 
      0x86f,      0x1d4, 
      0x762,      0x71b, 
      0x762,       0x47, 
      0x751,      0x492, 
      0x751,      0x2bf, 
      0x73d,      0x532, 
      0x73d,      0x20b, 
      0x71c,      0x709, 
      0x71c,       0x13, 
      0x666,      0x3f1, 
      0x666,      0x275, 
      0x56b,      0x374, 
      0x56b,      0x1f7, 
      0x4ec,      0x3b9, 
      0x4ec,      0x133, 
      0x4b7,      0x265, 
      0x4b7,      0x252, 
      0x4a6,      0x397, 
      0x4a6,      0x10f, 
      0x425,      0x318, 
      0x425,      0x10d, 
      0x3ef,      0x370, 
      0x3ef,       0x7f, 
      0x385,      0x2cf, 
      0x385,       0xb6, 
      0x2f5,      0x276, 
      0x2f5,       0x7f, 
      0x2bf,      0x1e7, 
      0x2bf,       0xd8, 
      0x275,      0x17a, 
      0x275,       0xfb, 
      0x21c,      0x169, 
      0x21c,       0xb3, 
      0x208,      0x1c1, 
      0x208,       0x47, 
      0x1b1,      0x143, 
      0x1b1,       0x6e, 
      0x143,       0xc5, 
      0x143,       0x7e, 
      0x134,      0x121, 
      0x134,       0x13, 
       0xfc,       0xb5, 
       0xfc,       0x47, 
       0xc7,       0x6d, 
       0xc7,       0x5a, 
       0xa3,       0x6b, 
       0xa3,       0x38, 
       0x5a,       0x49, 
       0x5a,       0x11, 
       0x59,       0x46, 
       0x59,       0x13, 
       0x35,       0x24, 
       0x35,       0x11, 
       0x25,       0x14, 
       0x25,       0x11, 
       0x13,       0x12, 
       0x13,        0x1, 
	0x2,	    0x1};

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("out6c.dat","w");
/*******************/
/*  factor input   */
/*******************/
for (h=0; h<insize; h+=2) {
/******************/
/*  first pair	  */
/******************/
   a=input[2*h];
   b=input[2*h+1];
   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");
/******************/
/*  second pair   */
/******************/
   a=input[2*h];
   b=a-input[2*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[2*h+1];
   a=input[2*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);
}