/******************************************************************************/
/* */
/* COMPUTE 3N+1 SEQUENCE (tree for k>28, more efficient algorithm, */
/* several passes required) */
/* 01/15/10 (dkc) */
/* */
/* This C program is for the C64. The maximum limb length is 33. */
/* */
/******************************************************************************/
#include <math.h>
void sub64(unsigned int *a, unsigned int *b);
void add64(unsigned int *a, unsigned int *b);
void shift(unsigned int a, unsigned int b, unsigned int c, unsigned int *s);
void mul64_32(unsigned int a, unsigned int b, unsigned int c, unsigned int *d);
unsigned int subr2(unsigned int A, unsigned int B, unsigned int *P);
far unsigned int s[2097152]; // duplicate array, size=(order/12)/32
far unsigned int ho[256]; // histogram of limb lengths
far unsigned int he[66]; // histogram of sequence vectors
far unsigned int v[13]; // sequence vector
far unsigned int error[5]; // error
far unsigned int maxy[66*2]; // maximum y value array
far unsigned int g; // counter
far unsigned int l=33; // limb length
far unsigned int a=13; // length of sequence vector
far unsigned int b=66; // number of sequence vectors
//far unsigned int sv[1*1]={ // length=2, live only
// 1};
//far unsigned int sv[2*1]={ // length=4, live only
// 1, 1};
//far unsigned int sv[3*1]={ // length=7, live only
// 1, 2, 1};
//far unsigned int sv[4*1]={ // length=9, live only
// 1, 2, 1, 1};
//far unsigned int sv[5*2]={ // length=12, live only
// 1, 2, 2, 1, 1, // 986
// 1, 2, 1, 2, 1}; // 842
//far unsigned int sv[6*2]={ // length=14, live only
// 1, 2, 2, 1, 1, 1, // 3214
// 1, 2, 1, 2, 1, 1}; // 2782
//far unsigned int sv[7*5]={ // length=17, live only
// 1, 2, 2, 2, 1, 1, 1, // 14314
// 1, 2, 2, 1, 2, 1, 1, // 12586
// 1, 2, 2, 1, 1, 2, 1, // 11434
// 1, 2, 1, 2, 2, 1, 1, // 11290
// 1, 2, 1, 2, 1, 2, 1}; // 10138
//far unsigned int sv[8*5]={ // length=20, live only
// 1, 2, 2, 2, 2, 1, 1, 1, // 61630
// 1, 2, 2, 2, 1, 2, 1, 1, // 54718
// 1, 2, 2, 2, 1, 1, 2, 1, // 50110
// 1, 2, 2, 1, 2, 2, 1, 1, // 49534
// 1, 2, 2, 1, 2, 1, 2, 1}; // 44926
//far unsigned int sv[9*9]={ // length=22, live only
// 1, 2, 2, 2, 2, 1, 1, 1, 1, // 193082
// 1, 2, 2, 2, 1, 2, 1, 1, 1, // 172346
// 1, 2, 2, 2, 1, 1, 2, 1, 1, // 158522
// 1, 2, 2, 1, 2, 2, 1, 1, 1, // 156794
// 1, 2, 1, 2, 2, 2, 1, 1, 1, // 145130
// 1, 2, 2, 1, 2, 1, 2, 1, 1, // 142970
// 1, 2, 2, 1, 1, 2, 2, 1, 1, // 132602
// 1, 2, 1, 2, 2, 1, 2, 1, 1, // 131306
// 1, 2, 1, 2, 1, 2, 2, 1, 1}; // 120938
/* far unsigned int sv[10*19]={ // length=25, live only
1, 2, 2, 2, 2, 2, 1, 1, 1, 1, // 811694
1, 2, 2, 2, 2, 1, 2, 1, 1, 1, // 728750
1, 2, 2, 2, 2, 1, 1, 2, 1, 1, // 673454
1, 2, 2, 2, 1, 2, 2, 1, 1, 1, // 666542
1, 2, 2, 2, 2, 1, 1, 1, 2, 1, // 636590
1, 2, 2, 1, 2, 2, 2, 1, 1, 1, // 619886
1, 2, 2, 2, 1, 2, 1, 2, 1, 1, // 611246
1, 2, 1, 2, 2, 2, 2, 1, 1, 1, // 584894
1, 2, 2, 2, 1, 2, 1, 1, 2, 1, // 574382
1, 2, 2, 2, 1, 1, 2, 2, 1, 1, // 569774
1, 2, 2, 1, 2, 2, 1, 2, 1, 1, // 564590
1, 2, 2, 2, 1, 1, 2, 1, 2, 1, // 532910
1, 2, 1, 2, 2, 2, 1, 2, 1, 1, // 529598
1, 2, 2, 1, 2, 2, 1, 1, 2, 1, // 527726
1, 2, 2, 1, 2, 1, 2, 2, 1, 1, // 523118
1, 2, 1, 2, 2, 2, 1, 1, 2, 1, // 492734
1, 2, 1, 2, 2, 1, 2, 2, 1, 1, // 488126
1, 2, 2, 1, 2, 1, 2, 1, 2, 1, // 486254
1, 2, 1, 2, 2, 1, 2, 1, 2, 1}; // 451262 */
/* far unsigned int sv[11*23]={ // length=27, live only
1, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1, // 2500618
1, 2, 2, 2, 2, 1, 2, 1, 1, 1, 1, // 2251786
1, 2, 2, 2, 2, 1, 1, 2, 1, 1, 1, // 2085898
1, 2, 2, 2, 1, 2, 2, 1, 1, 1, 1, // 2065162
1, 2, 2, 2, 2, 1, 1, 1, 2, 1, 1, // 1975306
1, 2, 2, 1, 2, 2, 2, 1, 1, 1, 1, // 1925194
1, 2, 2, 2, 1, 2, 1, 2, 1, 1, 1, // 1899274
1, 2, 1, 2, 2, 2, 2, 1, 1, 1, 1, // 1820218
1, 2, 2, 2, 1, 2, 1, 1, 2, 1, 1, // 1788682
1, 2, 2, 2, 1, 1, 2, 2, 1, 1, 1, // 1774858
1, 2, 2, 1, 2, 2, 1, 2, 1, 1, 1, // 1759306
1, 2, 2, 2, 1, 1, 2, 1, 2, 1, 1, // 1664266
1, 2, 1, 2, 2, 2, 1, 2, 1, 1, 1, // 1654330
1, 2, 2, 1, 2, 2, 1, 1, 2, 1, 1, // 1648714
1, 2, 2, 1, 2, 1, 2, 2, 1, 1, 1, // 1634890
1, 2, 1, 2, 2, 2, 1, 1, 2, 1, 1, // 1543738
1, 2, 2, 1, 1, 2, 2, 2, 1, 1, 1, // 1541578
1, 2, 1, 2, 2, 1, 2, 2, 1, 1, 1, // 1529914
1, 2, 2, 1, 2, 1, 2, 1, 2, 1, 1, // 1524298
1, 2, 1, 2, 1, 2, 2, 2, 1, 1, 1, // 1436602
1, 2, 2, 1, 1, 2, 2, 1, 2, 1, 1, // 1430986
1, 2, 1, 2, 2, 1, 2, 1, 2, 1, 1, // 1419322
1, 2, 1, 2, 1, 2, 2, 1, 2, 1, 1}; // 1326010 */
/* far unsigned int sv[12*66]={ // length=30, live only
1, 2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1, // 10356766
1, 2, 2, 2, 2, 2, 1, 2, 1, 1, 1, 1, // 9361438
1, 2, 2, 2, 2, 2, 1, 1, 2, 1, 1, 1, // 8697886
1, 2, 2, 2, 2, 1, 2, 2, 1, 1, 1, 1, // 8614942
1, 2, 2, 2, 2, 2, 1, 1, 1, 2, 1, 1, // 8255518
1, 2, 2, 2, 1, 2, 2, 2, 1, 1, 1, 1, // 8055070
1, 2, 2, 2, 2, 2, 1, 1, 1, 1, 2, 1, // 7960606
1, 2, 2, 2, 2, 1, 2, 1, 2, 1, 1, 1, // 7951390
1, 2, 2, 1, 2, 2, 2, 2, 1, 1, 1, 1, // 7635166
1, 2, 2, 2, 2, 1, 2, 1, 1, 2, 1, 1, // 7509022
1, 2, 2, 2, 2, 1, 1, 2, 2, 1, 1, 1, // 7453726
1, 2, 2, 2, 1, 2, 2, 1, 2, 1, 1, 1, // 7391518
1, 2, 1, 2, 2, 2, 2, 2, 1, 1, 1, 1, // 7320238
1, 2, 2, 2, 2, 1, 2, 1, 1, 1, 2, 1, // 7214110
1, 2, 2, 2, 2, 1, 1, 2, 1, 2, 1, 1, // 7011358
1, 2, 2, 1, 2, 2, 2, 1, 2, 1, 1, 1, // 6971614
1, 2, 2, 2, 1, 2, 2, 1, 1, 2, 1, 1, // 6949150
1, 2, 2, 2, 1, 2, 1, 2, 2, 1, 1, 1, // 6893854
1, 2, 2, 2, 2, 1, 1, 2, 1, 1, 2, 1, // 6716446
1, 2, 2, 2, 2, 1, 1, 1, 2, 2, 1, 1, // 6679582
1, 2, 1, 2, 2, 2, 2, 1, 2, 1, 1, 1, // 6656686
1, 2, 2, 2, 1, 2, 2, 1, 1, 1, 2, 1, // 6654238
1, 2, 2, 1, 2, 2, 2, 1, 1, 2, 1, 1, // 6529246
1, 2, 2, 2, 1, 1, 2, 2, 2, 1, 1, 1, // 6520606
1, 2, 2, 1, 2, 2, 1, 2, 2, 1, 1, 1, // 6473950
1, 2, 2, 2, 1, 2, 1, 2, 1, 2, 1, 1, // 6451486
1, 2, 2, 2, 2, 1, 1, 1, 2, 1, 2, 1, // 6384670
1, 2, 2, 1, 2, 2, 2, 1, 1, 1, 2, 1, // 6234334
1, 2, 1, 2, 2, 2, 2, 1, 1, 2, 1, 1, // 6214318
1, 2, 1, 2, 2, 2, 1, 2, 2, 1, 1, 1, // 6159022
1, 2, 2, 2, 1, 2, 1, 2, 1, 1, 2, 1, // 6156574
1, 2, 2, 2, 1, 2, 1, 1, 2, 2, 1, 1, // 6119710
1, 2, 2, 1, 2, 1, 2, 2, 2, 1, 1, 1, // 6100702
1, 2, 2, 2, 1, 1, 2, 2, 1, 2, 1, 1, // 6078238
1, 2, 2, 1, 2, 2, 1, 2, 1, 2, 1, 1, // 6031582
1, 2, 1, 2, 2, 2, 2, 1, 1, 1, 2, 1, // 5919406
1, 2, 2, 2, 1, 2, 1, 1, 2, 1, 2, 1, // 5824798
1, 2, 2, 1, 1, 2, 2, 2, 2, 1, 1, 1, // 5820766
1, 2, 1, 2, 2, 1, 2, 2, 2, 1, 1, 1, // 5785774
1, 2, 2, 2, 1, 1, 2, 2, 1, 1, 2, 1, // 5783326
1, 2, 2, 2, 1, 1, 2, 1, 2, 2, 1, 1, // 5746462
1, 2, 2, 1, 2, 2, 1, 2, 1, 1, 2, 1, // 5736670
1, 2, 1, 2, 2, 2, 1, 2, 1, 2, 1, 1, // 5716654
1, 2, 2, 1, 2, 2, 1, 1, 2, 2, 1, 1, // 5699806
1, 2, 2, 1, 2, 1, 2, 2, 1, 2, 1, 1, // 5658334
1, 2, 1, 2, 1, 2, 2, 2, 2, 1, 1, 1, // 5505838
1, 2, 2, 2, 1, 1, 2, 1, 2, 1, 2, 1, // 5451550
1, 2, 1, 2, 2, 2, 1, 2, 1, 1, 2, 1, // 5421742
1, 2, 2, 1, 2, 2, 1, 1, 2, 1, 2, 1, // 5404894
1, 2, 1, 2, 2, 2, 1, 1, 2, 2, 1, 1, // 5384878
1, 2, 2, 1, 1, 2, 2, 2, 1, 2, 1, 1, // 5378398
1, 2, 2, 1, 2, 1, 2, 2, 1, 1, 2, 1, // 5363422
1, 2, 1, 2, 2, 1, 2, 2, 1, 2, 1, 1, // 5343406
1, 2, 2, 1, 2, 1, 2, 1, 2, 2, 1, 1, // 5326558
1, 2, 1, 2, 2, 2, 1, 1, 2, 1, 2, 1, // 5089966
1, 2, 2, 1, 1, 2, 2, 2, 1, 1, 2, 1, // 5083486
1, 2, 1, 2, 1, 2, 2, 2, 1, 2, 1, 1, // 5063470
1, 2, 1, 2, 2, 1, 2, 2, 1, 1, 2, 1, // 5048494
1, 2, 2, 1, 1, 2, 2, 1, 2, 2, 1, 1, // 5046622
1, 2, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, // 5031646
1, 2, 1, 2, 2, 1, 2, 1, 2, 2, 1, 1, // 5011630
1, 2, 1, 2, 1, 2, 2, 2, 1, 1, 2, 1, // 4768558
1, 2, 2, 1, 1, 2, 2, 1, 2, 1, 2, 1, // 4751710
1, 2, 1, 2, 1, 2, 2, 1, 2, 2, 1, 1, // 4731694
1, 2, 1, 2, 2, 1, 2, 1, 2, 1, 2, 1, // 4716718
1, 2, 1, 2, 1, 2, 2, 1, 2, 1, 2, 1}; // 4436782 */
far unsigned int sv[13*66]={ // length=33, live only
1,2,2,2,2,2,2,2,1,1,1,1,1, // 42489946
1,2,2,2,2,2,2,1,2,1,1,1,1, // 38508634
1,2,2,2,2,2,2,1,1,2,1,1,1, // 35854426
1,2,2,2,2,2,1,2,2,1,1,1,1, // 35522650
1,2,2,2,2,2,2,1,1,1,2,1,1, // 34084954
1,2,2,2,2,1,2,2,2,1,1,1,1, // 33283162
1,2,2,2,2,2,2,1,1,1,1,2,1, // 32905306
1,2,2,2,2,2,1,2,1,2,1,1,1, // 32868442
1,2,2,2,1,2,2,2,2,1,1,1,1, // 31603546
1,2,2,2,2,2,1,2,1,1,2,1,1, // 31098970
1,2,2,2,2,2,1,1,2,2,1,1,1, // 30877786
1,2,2,2,2,1,2,2,1,2,1,1,1, // 30628954
1,2,2,1,2,2,2,2,2,1,1,1,1, // 30343834
1,2,2,2,2,2,1,2,1,1,1,2,1, // 29919322
1,2,2,2,2,2,1,1,2,1,2,1,1, // 29108314
1,2,2,2,1,2,2,2,1,2,1,1,1, // 28949338
1,2,2,2,2,1,2,2,1,1,2,1,1, // 28859482
1,2,2,2,2,1,2,1,2,2,1,1,1, // 28638298
1,2,2,2,2,2,1,1,2,1,1,2,1, // 27928666
1,2,2,2,2,2,1,1,1,2,2,1,1, // 27781210
1,2,2,1,2,2,2,2,1,2,1,1,1, // 27689626
1,2,2,2,2,1,2,2,1,1,1,2,1, // 27679834
1,2,2,2,1,2,2,2,1,1,2,1,1, // 27179866
1,2,2,2,2,1,1,2,2,2,1,1,1, // 27145306
1,2,2,2,1,2,2,1,2,2,1,1,1, // 26958682
1,2,2,2,2,1,2,1,2,1,2,1,1, // 26868826
1,2,2,2,2,2,1,1,1,2,1,2,1, // 26601562
1,2,2,2,1,2,2,2,1,1,1,2,1, // 26000218
1,2,2,1,2,2,2,2,1,1,2,1,1, // 25920154
1,2,2,1,2,2,2,1,2,2,1,1,1, // 25698970
1,2,2,2,2,1,2,1,2,1,1,2,1, // 25689178
1,2,2,2,2,1,2,1,1,2,2,1,1, // 25541722
1,2,2,2,1,2,1,2,2,2,1,1,1, // 25465690
1,2,2,2,2,1,1,2,2,1,2,1,1, // 25375834
1,2,2,2,1,2,2,1,2,1,2,1,1, // 25189210
1,2,2,1,2,2,2,2,1,1,1,2,1, // 24740506
1,2,2,2,2,1,2,1,1,2,1,2,1, // 24362074
1,2,2,2,1,1,2,2,2,2,1,1,1, // 24345946
1,2,2,1,2,2,1,2,2,2,1,1,1, // 24205978
1,2,2,2,2,1,1,2,2,1,1,2,1, // 24196186
1,2,2,2,2,1,1,2,1,2,2,1,1, // 24048730
1,2,2,2,1,2,2,1,2,1,1,2,1, // 24009562
1,2,2,1,2,2,2,1,2,1,2,1,1, // 23929498
1,2,2,2,1,2,2,1,1,2,2,1,1, // 23862106
1,2,2,2,1,2,1,2,2,1,2,1,1, // 23696218
1,2,2,1,2,1,2,2,2,2,1,1,1, // 23086234
1,2,2,2,2,1,1,2,1,2,1,2,1, // 22869082
1,2,2,1,2,2,2,1,2,1,1,2,1, // 22749850
1,2,2,2,1,2,2,1,1,2,1,2,1, // 22682458
1,2,2,1,2,2,2,1,1,2,2,1,1, // 22602394
1,2,2,2,1,1,2,2,2,1,2,1,1, // 22576474
1,2,2,2,1,2,1,2,2,1,1,2,1, // 22516570
1,2,2,1,2,2,1,2,2,1,2,1,1, // 22436506
1,2,2,2,1,2,1,2,1,2,2,1,1, // 22369114
1,2,2,1,2,1,2,2,2,1,2,1,1, // 21316762
1,2,2,1,2,2,1,2,2,1,1,2,1, // 21256858
1,2,2,2,1,1,2,2,1,2,2,1,1, // 21249370
1,2,2,2,1,2,1,2,1,2,1,2,1, // 21189466
1,2,2,1,2,2,2,1,1,2,1,2,1, // 21422746
1,2,2,2,1,1,2,2,2,1,1,2,1, // 21396826
1,2,2,1,2,2,1,2,1,2,2,1,1, // 21109402
1,2,2,1,2,1,2,2,2,1,1,2,1, // 20137114
1,2,2,2,1,1,2,2,1,2,1,2,1, // 20069722
1,2,2,1,2,1,2,2,1,2,2,1,1, // 19989658
1,2,2,1,2,2,1,2,1,2,1,2,1, // 19929754
1,2,2,1,2,1,2,2,1,2,1,2,1}; // 18810010
//far unsigned int z[1]={2}; // length=2, live only
//far unsigned int z[1]={10}; // length=4, live only
//far unsigned int z[1]={58}; // length=7, live only
//far unsigned int z[1]={206}; // length=9, live only
//far unsigned int z[2]={ // length=12, live only
// 986,842};
//far unsigned int z[2]={ // length=14, live only
// 2782,3214};
//far unsigned int z[5]={ // length=17, live only
// 14314,11434,12586,10138,11290};
//far unsigned int z[5]={ // length=20, live only
// 54718,49534,50110,44926,61630};
//far unsigned int z[9]={ // length=22, live only
// 156794,158522,172346,193082,145130,142970,132602,131306,120938};
//far unsigned int z[19]={ // length=25, live only
// 666542,532910,569774,574382,728750,611246,636590,673454,811694,619886,486254,
// 523118,527726,564590,451262,492734,584894,488126,529598};
//far unsigned int z[23]={ // length=27, live only
// 1788682,1654330,2065162,1975306,2251786,1774858,1524298,1899274,1648714,
// 2500618,1925194,1541578,1326010,1634890,1419322,1759306,1529914,1543738,
// 1820218,1664266,1430986,2085898,1436602};
//far unsigned int z[66]={ // length=30, live only
// 10356766,9361438,8697886,8614942,8255518,8055070,7960606,7951390,7635166,
// 7509022,7453726,7391518,7320238,7214110,7011358,6971614,6949150,6893854,
// 6716446,6679582,6656686,6654238,6529246,6520606,6473950,6451486,6384670,
// 6234334,6214318,6159022,6156574,6119710,6100702,6078238,6031582,5919406,
// 5824798,5820766,5785774,5783326,5746462,5736670,5716654,5699806,5658334,
// 5505838,5451550,5421742,5404894,5384878,5378398,5363422,5343406,5326558,
// 5089966,5083486,5063470,5048494,5046622,5031646,5011630,4768558,4751710,
// 4731694,4716718,4436782};
far unsigned int z[66]={ // length=33, live only
38508634,35854426,35522650,34084954,33283162,32905306,32868442,31603546,
31098970,30877786,30343834,29919322,28949338,28859482,28638298,27928666,
27781210,27689626,27679834,27179866,27145306,26958682,26868826,26601562,
26000218,25920154,25698970,25689178,25541722,25465690,25189210,24740506,
24362074,24345946,24196186,24048730,24009562,23862106,23696218,23086234,
22869082,22749850,22682458,22602394,22576474,22436506,22369114,21422746,
21396826,21316762,21256858,21249370,21189466,21109402,20137114,20069722,
19989658,19929754,18810010,42489946,30628954,29108314,25375834,24205978,
23929498,22516570};
//
int main () {
unsigned int kay=32; // k
//
// kay=29, stage=1,3
// kay=30, stage=1,3,5,7
// kay=31, stage=1,3,5,7,9,11,13,15
// kay=32, stage=1,3,5,7,9,11,13,15,17,19,21,23,25,27,29,31
// kay=33, stage=1,3,5,7,9,11,13,15,17,19,21,23,25,27,29,31,33,35,37,39,41,43,
// 45,47,49,51,53,55,57,59,61,63
//
unsigned int C[2],I[2],K[2],O[2],P[4],S[2],T[2],U[2],V[2],W[3],X[2],Y[2],Z[2];
unsigned int D[2],E[3],F[2],G[2],H[2],J[2];
unsigned int d,e,f,i,j,n,t,u,mask,flag,test,count,first,flagn; // indices
unsigned int stage; // stage (odd)
unsigned int num[19]={1,1,7,5,17,47,13,217,295,139,1909,1631,3299,
13085,6487,46075,84997,7153,502829};
unsigned int den[19]={4,8,16,32,64,128,256,512,1024,2048,4096,8192,16384,
32768,65536,131072,262144,524288,2097152};
unsigned int len[19]={2,4,5,7,9,10,12,14,15,17,18,20,22,23,25,27,28,30,33};
unsigned int y[40]={0,3,6,8,11, // B (invalid lengths)
13,16,19,21,24, // B
26,29,32,34,37, // B
39,42,44,47,50, // C
52,55,57,60,63, // C
65,68,70,73,75, // D
78,81,83,86,88, // D
91,94,96,99,101}; // D
for (i=0; i<a; i++) // clear sequence vector
v[i]=0;
error[0]=0;
error[1]=0;
error[2]=0;
error[3]=0;
error[4]=0;
for (i=0; i<256; i++) // clear histogram of lengths
ho[i]=0;
for (i=0; i<66; i++) {
he[i]=0;
maxy[2*i]=0;
maxy[2*i+1]=0;
}
g=0; // clear counter
if (kay<32) { // compute order
O[0]=0;
O[1]=1<<kay;
}
else {
if (kay!=32)
O[0]=1<<(kay-32);
else
O[0]=1;
O[1]=0;
}
Z[0]=O[0]; // order/3
Z[1]=O[1];
T[0]=O[0];
T[1]=O[1];
add64(O, T);
add64(T, O); // order=(1<<kay)*3
shift(O[0], O[1], 1, X); // save order/2
/*********************/
/* begin outer loop */
/*********************/
for (stage=1; stage<=31; stage+=2) {
shift(O[0], O[1], 1, I); // i=order/2
shift(O[0], O[1], 2, C); // loop count=order/4
for (i=0; i<2097152; i++) // clear duplicate array
s[i]=0;
//
// limbs ending in elements of A, B, C, and D
//
/*********************/
/* begin outer loop */
/*********************/
aloop:
if ((I[1]&3)!=0) // check if 4 divides i
goto hskip;
shift(I[0], I[1], 2, T); // i/4
U[0]=0;
U[1]=2;
sub64(T, U); // i-8
flag=subr2(U[0], U[1], P); // check if 12 divides i-8
if (flag!=0)
goto bskip;
hskip:
K[0]=I[0]; // k=i;
K[1]=I[1];
flag=subr2(K[0], K[1], P); // check if 3 divides k
if (flag!=0)
goto askip;
T[0]=0;
T[1]=1;
sub64(K, T); // k-1
flag=subr2(T[0], T[1], P); // check if 3 divides k-1
if (flag==0)
goto askip;
K[0]=P[0]; // k=(k-1)/3
K[1]=P[1];
flag=subr2(K[0], K[1], P); // check if 3 divides k
if (flag!=0)
goto bskip;
add64(K, K); // k=k*2
/***********************/
/* begin inner loop */
/***********************/
bloop:
test=1;
T[0]=X[0];
T[1]=X[1];
sub64(K, T); // k-order/2
if ((T[0]&0x80000000)==0)
test=0;
T[0]=0;
T[1]=1;
sub64(K, T); // k-1
flag=subr2(T[0], T[1], P); // check if 3 divides k-1
if ((flag==0)&&(test==0))
goto askip;
if (flag!=0) {
K[0]=P[0]; // k=(k-1)/3
K[1]=P[1];
flag=subr2(K[0], K[1], P); // check if 3 divide k
if (flag!=0)
goto bskip;
add64(K, K); // k=k*2;
}
else
add64(K, K); // k=k*2
goto bloop;
/***********************/
/* end inner loop */
/***********************/
askip:
S[0]=K[0]; // save starting element
S[1]=K[1];
n=1; // set length
cloop:
if ((K[1]&1)==0) {
shift(K[0], K[1], 1, K);
n=n+1; // increment length
goto cloop;
}
for (j=1; j<1000000; j++) { // iterate until end of limb
T[0]=K[0];
T[1]=K[1];
add64(K, T); // 2*k
add64(K, T); // 3*k
Y[0]=0;
Y[1]=1;
add64(T, Y); // h=3*k+1
T[0]=O[0];
T[1]=O[1];
sub64(Y, T); // h-order
if ((T[0]&0x80000000)!=0)
goto cskip;
if (kay<29) {
T[0]=Z[0]; // order/3
T[1]=Z[1];
sub64(K, T); // k-(order/3)
U[0]=0;
U[1]=1;
sub64(T, U); // k-(order/3)-1
shift(U[0], U[1], 1, T); // t=((k-order/3))-1)/2
}
else {
T[0]=0;
T[1]=stage;
sub64(K, T); // k-stage
mask=(1<<(kay-29+2))-1;
if ((T[1]&mask)!=0) // check if 2^x divides k-stage
goto bskip;
T[0]=Z[0];
T[1]=Z[1];
sub64(K, T); // k-(order/3)
U[0]=0;
U[1]=stage;
sub64(T, U); // k-(order/3)-stage
shift(U[0], U[1], kay-29+2, T);
}
t=T[1];
u=t-(t>>5)*32; // fractional portion of index
t=t>>5; // integer portion of index
mask=1<<u; // set mask
if ((s[t]&mask)==0) // check if bit not set
s[t]=s[t]|mask; // set bit in array
else // already set
goto bskip;
//
g=g+1; // increment counter
if (n<256) // check length
ho[n]=ho[n]+1; // histogram length
else {
error[0]=1; // set error
ho[0]=0xffffffff; // set flag
goto zskip;
}
if (n!=l) // check length
goto bskip;
flag=subr2(S[0], S[1], P); // check if 3 divides m
if (flag==1) // dead limb
goto bskip;
shift(Y[0], Y[1], 1, V); // h/2
sub64(S, V); // r=m-(h/2)
flagn=0; // check for negative r
if ((V[0]&0x80000000)!=0) {
D[0]=0;
D[1]=0;
sub64(D, V);
flagn=1;
}
for (f=0; f<19; f++) {
if (n==len[f]) {
mul64_32(S[0], S[1], num[f], W);
F[0]=W[1];
F[1]=W[2];
mul64_32(V[0], V[1], den[f], E);
G[0]=E[1];
G[1]=E[2];
if (flagn==0)
sub64(F, G);
else {
sub64(G, F);
G[0]=F[0];
G[1]=F[1];
}
if (G[0]!=0) {
error[0]=14;
error[1]=W[1];
error[2]=W[2];
error[3]=E[1];
error[4]=E[2];
goto zskip;
}
flag=0;
for (e=0; e<b; e++) {
if (G[1]==z[e]) {
flag=z[e];
goto fskip;
}
}
error[0]=G[1]; // e value not found
goto zskip;
fskip: if (l==2) {
v[0]=1;
f=1;
goto dskip;
}
H[0]=S[0]; // save m
H[1]=S[1];
f=0;
if ((S[1]&1)==0) {
count=0;
while ((S[1]&1)==0) {
count=count+1;
shift(S[0], S[1], 1, S);
}
v[0]=count;
f=1;
}
first=1;
while ((S[0]!=K[0])||(S[1]!=K[1])) {
if ((S[1]&1)==0) {
shift(S[0], S[1], 1, S);
count=count+1;
}
else {
D[0]=S[0];
D[1]=S[1];
add64(S, S);
add64(D, S);
D[0]=0;
D[1]=1;
add64(D, S);
if (first==0) {
v[f]=count;
f=f+1;
if (f>a) {
error[0]=9;
error[1]=H[0];
error[2]=H[1];
error[3]=K[0];
error[4]=K[1];
goto zskip;
}
}
else
first=0;
count=0;
}
}
v[f]=count;
f=f+1;
dskip: if (f!=a) {
error[0]=10;
goto zskip;
}
for (d=0; d<b; d++) {
for (j=0; j<a; j++) {
if (v[j]!=sv[j+a*d])
goto eskip;
}
he[d]=he[d]+1;
J[0]=maxy[2*d];
J[1]=maxy[2*d+1];
sub64(H, J);
if ((J[0]&0x80000000)==0) {
maxy[2*d]=H[0];
maxy[2*d+1]=H[1];
}
goto bskip;
eskip: n=0;
}
error[0]=flag; // sequence vector not found
error[1]=H[0];
error[2]=H[1];
error[3]=K[0];
error[4]=K[1];
goto zskip;
}
}
goto bskip;
cskip:
K[0]=Y[0]; // k=h
K[1]=Y[1];
if ((K[1]&7)==0) // check if 8 divides k
goto bskip;
n=n+1; // increment length
dloop:
if ((K[1]&1)==0) {
shift(K[0], K[1], 1, K); // k=k>>1
n=n+1; // increment length
goto dloop;
}
}
error[0]=2; // limb not found
ho[0]=0xffffffff;
goto zskip;
bskip:
T[0]=0;
T[1]=2;
add64(I, T);
I[0]=T[0]; // i=i+2
I[1]=T[1];
T[0]=0;
T[1]=1;
sub64(C,T);
C[0]=T[0]; // loop count=loop count-1
C[1]=T[1];
if ((C[0]!=0)||(C[1]!=0))
goto aloop;
/*********************/
/* end outer loop */
/*********************/
}
/*********************/
/* end outer loop */
/*********************/
for (i=0; i<40; i++) {
if (ho[y[i]]!=0) {
error[0]=13;
goto zskip;
}
}
zskip:
return(0);
}