/*  DETERMINE IF 2^(K+L)-3^K INCREASES MONOTONICALLY (for generalized	      */
/*  continued-fraction convergents of log(3)/log(2))			      */
/*  03/12/13 (dkc)							      */
/*									      */
/*  This C program computes 2^l-3^m where (l,m) are continued-fraction	      */
/*  convergents of log(3)/log(2) (excluding (2,1), (4,2), (6,4), and (9,6)).  */
/*									      */
/******************************************************************************/
#include <math.h>
void mult3(unsigned int *c, unsigned int n);
void lshiftn(unsigned int *a, unsigned int *b, unsigned int shift, unsigned int n);
void addn(unsigned int *a, unsigned int *b, unsigned int n);
void copyn(unsigned int *a, unsigned int *b, unsigned int n);
void setn(unsigned int *a, unsigned int b, unsigned int n);
void negn(unsigned int *a, unsigned int n);
void dummy(unsigned int a);
far unsigned int error[6];
far unsigned int S[65536+32768];
far unsigned int ln[221*2]={
// 1, 1,  // exclude
// 2, 1,  // exclude
 3, 2, 
// 4, 2,  // exclude
 5, 3, 
// 6, 4,  // exclude
 8, 5, 
// 9, 6,  // exclude
 11, 7, 
 13, 8,   // extra (length=20)
 16, 10, 
 19, 12, 
 24, 15, 
 27, 17, 
 32, 20,  // extra
 35, 22,  // extra (length=56)
 38, 24, 
 46, 29, 
 54, 34,  // extra
 57, 36, 
 65, 41, 
 76, 48, 
 84, 53, 
 130, 82, 
 149, 94, 
 168, 106, 
 233, 147, 
 252, 159, 
 317, 200, 
 336, 212, 
 401, 253, 
 420, 265, 
 485, 306, 
 504, 318, 
 569, 359, 
 970, 612, 
 1054, 665, 
 1455, 918, 
 1539, 971, 
 2108, 1330, 
 2593, 1636, 
 3162, 1995, 
 3647, 2301, 
 4216, 2660, 
 4701, 2966, 
 5270, 3325, 
 5755, 3631, 
 6324, 3990, 
 6809, 4296, 
 7378, 4655, 
 7863, 4961, 
 8432, 5320, 
 8917, 5626, 
 9486, 5985, 
 9971, 6291, 
 10540, 6650, 
 11025, 6956, 
 11594, 7315, 
 12079, 7621, 
 12648, 7980, 
 13133, 8286, 
 13702, 8645, 
 14187, 8951, 
 14756, 9310, 
 15241, 9616, 
 15810, 9975, 
 16295, 10281, 
 16864, 10640, 
 17349, 10946, 
 17918, 11305, 
 18403, 11611, 
 18972, 11970, 
 19457, 12276, 
 20026, 12635, 
 20511, 12941, 
 21080, 13300, 
 21565, 13606, 
 22134, 13965, 
 22619, 14271, 
 23188, 14630, 
 23673, 14936, 
 24242, 15295, 
 24727, 15601, 
 25296, 15960, 
 25781, 16266, 
 49454, 31202, 
 50508, 31867, 
 74181, 46803, 
 75235, 47468, 
 101016, 63734, 
 125743, 79335, 
 151524, 95601, 
 176251, 111202, 
 251486, 158670, 
 301994, 190537, 
 352502, 222404, 
 478245, 301739, 
 603988, 381074, 
 780239, 492276, 
 905982, 571611, 
 1082233, 682813, 
 1207976, 762148, 
 1384227, 873350, 
 1509970, 952685, 
 1686221, 1063887, 
 1811964, 1143222, 
 1988215, 1254424, 
 2113958, 1333759, 
 2290209, 1444961, 
 2415952, 1524296, 
 2592203, 1635498, 
 2717946, 1714833, 
 2894197, 1826035, 
 3019940, 1905370, 
 3196191, 2016572, 
 3321934, 2095907, 
 3498185, 2207109, 
 3623928, 2286444, 
 3800179, 2397646, 
 3925922, 2476981, 
 4102173, 2588183, 
 4227916, 2667518, 
 4404167, 2778720, 
 4529910, 2858055, 
 4706161, 2969257, 
 4831904, 3048592, 
 5008155, 3159794, 
 5133898, 3239129, 
 5310149, 3350331, 
 5435892, 3429666, 
 5612143, 3540868, 
 5737886, 3620203, 
 5914137, 3731405, 
 6039880, 3810740, 
 6216131, 3921942, 
 6341874, 4001277, 
 6518125, 4112479, 
 6643868, 4191814, 
 6820119, 4303016, 
 6945862, 4382351, 
 7122113, 4493553, 
 7247856, 4572888, 
 7424107, 4684090, 
 7549850, 4763425, 
 7726101, 4874627, 
 7851844, 4953962, 
 8028095, 5065164, 
 8153838, 5144499, 
 8330089, 5255701, 
 8455832, 5335036, 
 8632083, 5446238, 
 8757826, 5525573, 
 8934077, 5636775, 
 9059820, 5716110, 
 9236071, 5827312, 
 9361814, 5906647, 
 9538065, 6017849, 
 9663808, 6097184, 
 9840059, 6208386, 
 9965802, 6287721, 
 10142053, 6398923, 
 10267796, 6478258, 
 10444047, 6589460, 
 10569790, 6668795, 
 10746041, 6779997, 
 10871784, 6859332, 
 11048035, 6970534, 
 11173778, 7049869, 
 11350029, 7161071, 
 11475772, 7240406, 
 11652023, 7351608, 
 11777766, 7430943, 
 11954017, 7542145, 
 12079760, 7621480, 
 12256011, 7732682, 
 12381754, 7812017, 
 12558005, 7923219, 
 12683748, 8002554, 
 12859999, 8113756, 
 12985742, 8193091, 
 13161993, 8304293, 
 13287736, 8383628, 
 13463987, 8494830, 
 13589730, 8574165, 
 13765981, 8685367, 
 13891724, 8764702, 
 14067975, 8875904, 
 14193718, 8955239, 
 14369969, 9066441, 
 14495712, 9145776, 
 14671963, 9256978, 
 14797706, 9336313, 
 14973957, 9447515, 
 15099700, 9526850, 
 15275951, 9638052, 
 15401694, 9717387, 
 15577945, 9828589, 
 15703688, 9907924, 
 15879939, 10019126, 
 16005682, 10098461, 
 16181933, 10209663, 
 16307676, 10288998, 
 16483927, 10400200, 
 16609670, 10479535, 
 16785921, 10590737, 
 16911664, 10670072, 
 17087915, 10781274, 
 33571842, 21181474, 
 33873836, 21372011, 
 34175830, 21562548, 
 50961751, 32153285, 
 51263745, 32343822, 
 68049666, 42934559, 
 68351660, 43125096, 
 85137581, 53715833, 
 85439575, 53906370, 
 102225496, 64497107, 
 170275162, 107431666, 
 187363077, 118212940,
 255412743, 161147499,
 272500658, 171928773, 
 340550324, 214863332, 
 357638239, 225644606, 
 545001316, 343857546, 
 630138897, 397573379, 
 715276478, 451289212};

int main () {
unsigned int A[65536+32768],B[65536+32768];
unsigned int m=65536+32768;
unsigned int h,i,l,n;
error[0]=0;
error[1]=0;
error[2]=0;
error[3]=0;
error[4]=0;
error[5]=0;
setn(S, 0, m);
for (i=0; i<221; i++) {
   l=ln[2*i];			// length of cycle
   n=ln[2*i+1]; 		// number of odd elements in loop
   error[3]=i;
   error[4]=n;
   if ((l>>5)>m) {		// 2**l-3**n is too big
      error[0]=5;
      error[1]=l;
      error[2]=n;
      goto zskip;
      }
   setn(A, 1, m);
   lshiftn(A, B, l, m); 		// 2**l
   setn(A, 1, m);
   for (h=0; h<n; h++) {		// 3**n
      mult3(A, m);
      if ((A[0]&0xff000000)!=0) {
	 error[0]=2;
	 goto zskip;
	 }
      }
   negn(A, m);
   addn(B, A, m);			// 2**l-3**n
   if ((A[0]&0x80000000)!=0)		// negate 2**l-3**n
      negn(A, m);
   copyn(S, B, m);
   negn(B, m);
   addn(A, B, m);
   if ((B[0]&0x80000000)!=0) {		// compare to previous value
      error[0]=1;
      error[1]=l;
      error[2]=n;
      goto zskip;
      }
   copyn(A, S, m);			// save current value
   dummy(0);
   }
zskip:
return(0);
}