[BACK]Return to gfs.c CVS log [TXT][DIR] Up to [local] / OpenXM_contrib2 / asir2000 / engine

Annotation of OpenXM_contrib2/asir2000/engine/gfs.c, Revision 1.6

1.1       noro        1: /*
                      2:  * Copyright (c) 1994-2000 FUJITSU LABORATORIES LIMITED
                      3:  * All rights reserved.
                      4:  *
                      5:  * FUJITSU LABORATORIES LIMITED ("FLL") hereby grants you a ligfsted,
                      6:  * non-exclusive and royalty-free license to use, copy, modify and
                      7:  * redistribute, solely for non-commercial and non-profit purposes, the
                      8:  * computer program, "Risa/Asir" ("SOFTWARE"), subject to the terms and
                      9:  * conditions of this Agreement. For the avoidance of doubt, you acquire
                     10:  * only a ligfsted right to use the SOFTWARE hereunder, and FLL or any
                     11:  * third party developer retains all rights, including but not ligfsted to
                     12:  * copyrights, in and to the SOFTWARE.
                     13:  *
                     14:  * (1) FLL does not grant you a license in any way for commercial
                     15:  * purposes. You may use the SOFTWARE only for non-commercial and
                     16:  * non-profit purposes only, such as acadegfsc, research and internal
                     17:  * business use.
                     18:  * (2) The SOFTWARE is protected by the Copyright Law of Japan and
                     19:  * international copyright treaties. If you make copies of the SOFTWARE,
                     20:  * with or without modification, as pergfstted hereunder, you shall affix
                     21:  * to all such copies of the SOFTWARE the above copyright notice.
                     22:  * (3) An explicit reference to this SOFTWARE and its copyright owner
                     23:  * shall be made on your publication or presentation in any form of the
                     24:  * results obtained by use of the SOFTWARE.
                     25:  * (4) In the event that you modify the SOFTWARE, you shall notify FLL by
                     26:  * e-mail at risa-adgfsn@sec.flab.fujitsu.co.jp of the detailed specification
                     27:  * for such modification or the source code of the modified part of the
                     28:  * SOFTWARE.
                     29:  *
                     30:  * THE SOFTWARE IS PROVIDED AS IS WITHOUT ANY WARRANTY OF ANY KIND. FLL
                     31:  * MAKES ABSOLUTELY NO WARRANTIES, EXPRESSED, IMPLIED OR STATUTORY, AND
                     32:  * EXPRESSLY DISCLAIMS ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS
                     33:  * FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT OF THIRD PARTIES'
                     34:  * RIGHTS. NO FLL DEALER, AGENT, EMPLOYEES IS AUTHORIZED TO MAKE ANY
                     35:  * MODIFICATIONS, EXTENSIONS, OR ADDITIONS TO THIS WARRANTY.
                     36:  * UNDER NO CIRCUMSTANCES AND UNDER NO LEGAL THEORY, TORT, CONTRACT,
                     37:  * OR OTHERWISE, SHALL FLL BE LIABLE TO YOU OR ANY OTHER PERSON FOR ANY
                     38:  * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, PUNITIVE OR CONSEQUENTIAL
                     39:  * DAMAGES OF ANY CHARACTER, INCLUDING, WITHOUT LIMITATION, DAMAGES
                     40:  * ARISING OUT OF OR RELATING TO THE SOFTWARE OR THIS AGREEMENT, DAMAGES
                     41:  * FOR LOSS OF GOODWILL, WORK STOPPAGE, OR LOSS OF DATA, OR FOR ANY
                     42:  * DAMAGES, EVEN IF FLL SHALL HAVE BEEN INFORMED OF THE POSSIBILITY OF
                     43:  * SUCH DAMAGES, OR FOR ANY CLAIM BY ANY OTHER PARTY. EVEN IF A PART
                     44:  * OF THE SOFTWARE HAS BEEN DEVELOPED BY A THIRD PARTY, THE THIRD PARTY
                     45:  * DEVELOPER SHALL HAVE NO LIABILITY IN CONNECTION WITH THE USE,
                     46:  * PERFORMANCE OR NON-PERFORMANCE OF THE SOFTWARE.
                     47:  *
1.6     ! noro       48:  * $OpenXM: OpenXM_contrib2/asir2000/engine/gfs.c,v 1.5 2001/05/28 08:22:01 noro Exp $
1.1       noro       49: */
                     50: #include "ca.h"
                     51:
                     52: /* q = p^n */
                     53:
1.2       noro       54: P current_gfs_ext;
                     55: int current_gfs_p;
1.1       noro       56: int current_gfs_q;
                     57: int current_gfs_q1;
                     58: int *current_gfs_plus1;
                     59: int *current_gfs_ntoi;
                     60: int *current_gfs_iton;
                     61:
                     62: void chsgngfs();
1.2       noro       63: void generate_defpoly_um();
                     64:
1.6     ! noro       65: struct prim_root_info {
        !            66:        int p;
        !            67:        int extdeg;
        !            68:        int defpoly;
        !            69:        int prim_root;
        !            70: };
        !            71:
        !            72: struct prim_root_info prim_root_info_tab[] = {
        !            73: {2,1,0,0}, {2,2,7,2}, {2,3,11,2}, {2,4,19,2}, {2,5,37,2}, {2,6,67,2},
        !            74: {2,7,131,2}, {2,8,283,3}, {2,9,515,7}, {2,10,1033,2}, {2,11,2053,2},
        !            75: {2,12,4105,3}, {2,13,8219,2}, {2,14,16417,7}, {2,15,32771,2}, {3,1,0,2},
        !            76: {3,2,10,4}, {3,3,34,3}, {3,4,86,3}, {3,5,250,3}, {3,6,734,3}, {3,7,2198,5},
        !            77: {3,8,6572,38}, {3,9,19747,3}, {3,10,59068,34}, {5,1,0,2}, {5,2,27,6},
        !            78: {5,3,131,9}, {5,4,627,6}, {5,5,3146,10}, {5,6,15632,5}, {7,1,0,3},
        !            79: {7,2,50,9}, {7,3,345,22}, {7,4,2409,12}, {7,5,16817,9}, {11,1,0,2},
        !            80: {11,2,122,15}, {11,3,1346,11}, {11,4,14654,11}, {13,1,0,2}, {13,2,171,15},
        !            81: {13,3,2199,15}, {13,4,28563,17}, {17,1,0,3}, {17,2,292,19}, {17,3,4933,17},
        !            82: {19,1,0,2}, {19,2,362,22}, {19,3,6861,29}, {23,1,0,5}, {23,2,530,25},
        !            83: {23,3,12193,23}, {29,1,0,2}, {29,2,843,30}, {29,3,24422,30}, {31,1,0,3},
        !            84: {31,2,962,35}, {31,3,29794,34}, {37,1,0,2}, {37,2,1371,41}, {37,3,50655,75},
        !            85: {41,1,0,6}, {41,2,1684,43}, {43,1,0,3}, {43,2,1850,45}, {47,1,0,5},
        !            86: {47,2,2210,49}, {53,1,0,2}, {53,2,2811,54}, {59,1,0,2}, {59,2,3482,62},
        !            87: {61,1,0,2}, {61,2,3723,63}, {67,1,0,2}, {67,2,4490,74}, {71,1,0,7},
        !            88: {71,2,5042,79}, {73,1,0,5}, {73,2,5334,76}, {79,1,0,3}, {79,2,6242,85},
        !            89: {83,1,0,2}, {83,2,6890,93}, {89,1,0,3}, {89,2,7924,91}, {97,1,0,5},
        !            90: {97,2,9414,101}, {101,1,0,2}, {101,2,10203,102},
        !            91: {103,1,0,5}, {103,2,10610,105}, {107,1,0,2}, {107,2,11450,109},
        !            92: {109,1,0,6}, {109,2,11883,111}, {113,1,0,3}, {113,2,12772,117},
        !            93: {127,1,0,3}, {127,2,16130,135}, {131,1,0,2}, {131,2,17162,134},
        !            94: {137,1,0,3}, {137,2,18772,145}, {139,1,0,2}, {139,2,19322,143},
        !            95: {149,1,0,2}, {149,2,22203,152}, {151,1,0,6}, {151,2,22802,160},
        !            96: {157,1,0,5}, {157,2,24651,159}, {163,1,0,2}, {163,2,26570,170},
        !            97: {167,1,0,5}, {167,2,27890,169}, {173,1,0,2}, {173,2,29931,174},
        !            98: {179,1,0,2}, {179,2,32042,182}, {181,1,0,2}, {181,2,32763,185},
        !            99: {191,1,0,19}, {191,2,36482,201}, {193,1,0,5}, {193,2,37254,198},
        !           100: {197,1,0,2}, {197,2,38811,200}, {199,1,0,3}, {199,2,39602,212},
        !           101: {211,1,0,2}, {211,2,44522,215}, {223,1,0,3}, {223,2,49730,225},
        !           102: {227,1,0,2}, {227,2,51530,229}, {229,1,0,6}, {229,2,52443,231},
        !           103: {233,1,0,3}, {233,2,54292,241}, {239,1,0,7}, {239,2,57122,247},
        !           104: {241,1,0,7}, {241,2,58088,248}, {251,1,0,6}, {251,2,63002,256},
        !           105: {257,1,0,3}, {263,1,0,5}, {269,1,0,2}, {271,1,0,6}, {277,1,0,5}, {281,1,0,3},
        !           106: {283,1,0,3}, {293,1,0,2}, {307,1,0,5}, {311,1,0,17}, {313,1,0,10},
        !           107: {317,1,0,2}, {331,1,0,3}, {337,1,0,10}, {347,1,0,2}, {349,1,0,2},
        !           108: {353,1,0,3}, {359,1,0,7}, {367,1,0,6}, {373,1,0,2}, {379,1,0,2},
        !           109: {383,1,0,5}, {389,1,0,2}, {397,1,0,5}, {401,1,0,3}, {409,1,0,21},
        !           110: {419,1,0,2}, {421,1,0,2}, {431,1,0,7}, {433,1,0,5}, {439,1,0,15},
        !           111: {443,1,0,2}, {449,1,0,3}, {457,1,0,13}, {461,1,0,2}, {463,1,0,3},
        !           112: {467,1,0,2}, {479,1,0,13}, {487,1,0,3}, {491,1,0,2}, {499,1,0,7},
        !           113: {503,1,0,5}, {509,1,0,2}, {521,1,0,3}, {523,1,0,2}, {541,1,0,2},
        !           114: {547,1,0,2}, {557,1,0,2}, {563,1,0,2}, {569,1,0,3}, {571,1,0,3},
        !           115: {577,1,0,5}, {587,1,0,2}, {593,1,0,3}, {599,1,0,7}, {601,1,0,7},
        !           116: {607,1,0,3}, {613,1,0,2}, {617,1,0,3}, {619,1,0,2}, {631,1,0,3},
        !           117: {641,1,0,3}, {643,1,0,11}, {647,1,0,5}, {653,1,0,2}, {659,1,0,2},
        !           118: {661,1,0,2}, {673,1,0,5}, {677,1,0,2}, {683,1,0,5}, {691,1,0,3},
        !           119: {701,1,0,2}, {709,1,0,2}, {719,1,0,11}, {727,1,0,5}, {733,1,0,6},
        !           120: {739,1,0,3}, {743,1,0,5}, {751,1,0,3}, {757,1,0,2}, {761,1,0,6},
        !           121: {769,1,0,11}, {773,1,0,2}, {787,1,0,2}, {797,1,0,2}, {809,1,0,3},
        !           122: {811,1,0,3}, {821,1,0,2}, {823,1,0,3}, {827,1,0,2}, {829,1,0,2},
        !           123: {839,1,0,11}, {853,1,0,2}, {857,1,0,3}, {859,1,0,2}, {863,1,0,5},
        !           124: {877,1,0,2}, {881,1,0,3}, {883,1,0,2}, {887,1,0,5}, {907,1,0,2},
        !           125: {911,1,0,17}, {919,1,0,7}, {929,1,0,3}, {937,1,0,5}, {941,1,0,2},
        !           126: {947,1,0,2}, {953,1,0,3}, {967,1,0,5}, {971,1,0,6}, {977,1,0,3},
        !           127: {983,1,0,5}, {991,1,0,6}, {997,1,0,7}, {1009,1,0,11}, {1013,1,0,3},
        !           128: {1019,1,0,2}, {1021,1,0,10}, {1031,1,0,14}, {1033,1,0,5}, {1039,1,0,3},
        !           129: {1049,1,0,3}, {1051,1,0,7}, {1061,1,0,2}, {1063,1,0,3}, {1069,1,0,6},
        !           130: {1087,1,0,3}, {1091,1,0,2}, {1093,1,0,5}, {1097,1,0,3}, {1103,1,0,5},
        !           131: {1109,1,0,2}, {1117,1,0,2}, {1123,1,0,2}, {1129,1,0,11}, {1151,1,0,17},
        !           132: {1153,1,0,5}, {1163,1,0,5}, {1171,1,0,2}, {1181,1,0,7}, {1187,1,0,2},
        !           133: {1193,1,0,3}, {1201,1,0,11}, {1213,1,0,2}, {1217,1,0,3}, {1223,1,0,5},
        !           134: {1229,1,0,2}, {1231,1,0,3}, {1237,1,0,2}, {1249,1,0,7}, {1259,1,0,2},
        !           135: {1277,1,0,2}, {1279,1,0,3}, {1283,1,0,2}, {1289,1,0,6}, {1291,1,0,2},
        !           136: {1297,1,0,10}, {1301,1,0,2}, {1303,1,0,6}, {1307,1,0,2}, {1319,1,0,13},
        !           137: {1321,1,0,13}, {1327,1,0,3}, {1361,1,0,3}, {1367,1,0,5}, {1373,1,0,2},
        !           138: {1381,1,0,2}, {1399,1,0,13}, {1409,1,0,3}, {1423,1,0,3}, {1427,1,0,2},
        !           139: {1429,1,0,6}, {1433,1,0,3}, {1439,1,0,7}, {1447,1,0,3}, {1451,1,0,2},
        !           140: {1453,1,0,2}, {1459,1,0,3}, {1471,1,0,6}, {1481,1,0,3}, {1483,1,0,2},
        !           141: {1487,1,0,5}, {1489,1,0,14}, {1493,1,0,2}, {1499,1,0,2}, {1511,1,0,11},
        !           142: {1523,1,0,2}, {1531,1,0,2}, {1543,1,0,5}, {1549,1,0,2}, {1553,1,0,3},
        !           143: {1559,1,0,19}, {1567,1,0,3}, {1571,1,0,2}, {1579,1,0,3}, {1583,1,0,5},
        !           144: {1597,1,0,11}, {1601,1,0,3}, {1607,1,0,5}, {1609,1,0,7}, {1613,1,0,3},
        !           145: {1619,1,0,2}, {1621,1,0,2}, {1627,1,0,3}, {1637,1,0,2}, {1657,1,0,11},
        !           146: {1663,1,0,3}, {1667,1,0,2}, {1669,1,0,2}, {1693,1,0,2}, {1697,1,0,3},
        !           147: {1699,1,0,3}, {1709,1,0,3}, {1721,1,0,3}, {1723,1,0,3}, {1733,1,0,2},
        !           148: {1741,1,0,2}, {1747,1,0,2}, {1753,1,0,7}, {1759,1,0,6}, {1777,1,0,5},
        !           149: {1783,1,0,10}, {1787,1,0,2}, {1789,1,0,6}, {1801,1,0,11}, {1811,1,0,6},
        !           150: {1823,1,0,5}, {1831,1,0,3}, {1847,1,0,5}, {1861,1,0,2}, {1867,1,0,2},
        !           151: {1871,1,0,14}, {1873,1,0,10}, {1877,1,0,2}, {1879,1,0,6}, {1889,1,0,3},
        !           152: {1901,1,0,2}, {1907,1,0,2}, {1913,1,0,3}, {1931,1,0,2}, {1933,1,0,5},
        !           153: {1949,1,0,2}, {1951,1,0,3}, {1973,1,0,2}, {1979,1,0,2}, {1987,1,0,2},
        !           154: {1993,1,0,5}, {1997,1,0,2}, {1999,1,0,3}, {2003,1,0,5}, {2011,1,0,3},
        !           155: {2017,1,0,5}, {2027,1,0,2}, {2029,1,0,2}, {2039,1,0,7}, {2053,1,0,2},
        !           156: {2063,1,0,5}, {2069,1,0,2}, {2081,1,0,3}, {2083,1,0,2}, {2087,1,0,5},
        !           157: {2089,1,0,7}, {2099,1,0,2}, {2111,1,0,7}, {2113,1,0,5}, {2129,1,0,3},
        !           158: {2131,1,0,2}, {2137,1,0,10}, {2141,1,0,2}, {2143,1,0,3}, {2153,1,0,3},
        !           159: {2161,1,0,23}, {2179,1,0,7}, {2203,1,0,5}, {2207,1,0,5}, {2213,1,0,2},
        !           160: {2221,1,0,2}, {2237,1,0,2}, {2239,1,0,3}, {2243,1,0,2}, {2251,1,0,7},
        !           161: {2267,1,0,2}, {2269,1,0,2}, {2273,1,0,3}, {2281,1,0,7}, {2287,1,0,19},
        !           162: {2293,1,0,2}, {2297,1,0,5}, {2309,1,0,2}, {2311,1,0,3}, {2333,1,0,2},
        !           163: {2339,1,0,2}, {2341,1,0,7}, {2347,1,0,3}, {2351,1,0,13}, {2357,1,0,2},
        !           164: {2371,1,0,2}, {2377,1,0,5}, {2381,1,0,3}, {2383,1,0,5}, {2389,1,0,2},
        !           165: {2393,1,0,3}, {2399,1,0,11}, {2411,1,0,6}, {2417,1,0,3}, {2423,1,0,5},
        !           166: {2437,1,0,2}, {2441,1,0,6}, {2447,1,0,5}, {2459,1,0,2}, {2467,1,0,2},
        !           167: {2473,1,0,5}, {2477,1,0,2}, {2503,1,0,3}, {2521,1,0,17}, {2531,1,0,2},
        !           168: {2539,1,0,2}, {2543,1,0,5}, {2549,1,0,2}, {2551,1,0,6}, {2557,1,0,2},
        !           169: {2579,1,0,2}, {2591,1,0,7}, {2593,1,0,7}, {2609,1,0,3}, {2617,1,0,5},
        !           170: {2621,1,0,2}, {2633,1,0,3}, {2647,1,0,3}, {2657,1,0,3}, {2659,1,0,2},
        !           171: {2663,1,0,5}, {2671,1,0,7}, {2677,1,0,2}, {2683,1,0,2}, {2687,1,0,5},
        !           172: {2689,1,0,19}, {2693,1,0,2}, {2699,1,0,2}, {2707,1,0,2}, {2711,1,0,7},
        !           173: {2713,1,0,5}, {2719,1,0,3}, {2729,1,0,3}, {2731,1,0,3}, {2741,1,0,2},
        !           174: {2749,1,0,6}, {2753,1,0,3}, {2767,1,0,3}, {2777,1,0,3}, {2789,1,0,2},
        !           175: {2791,1,0,6}, {2797,1,0,2}, {2801,1,0,3}, {2803,1,0,2}, {2819,1,0,2},
        !           176: {2833,1,0,5}, {2837,1,0,2}, {2843,1,0,2}, {2851,1,0,2}, {2857,1,0,11},
        !           177: {2861,1,0,2}, {2879,1,0,7}, {2887,1,0,5}, {2897,1,0,3}, {2903,1,0,5},
        !           178: {2909,1,0,2}, {2917,1,0,5}, {2927,1,0,5}, {2939,1,0,2}, {2953,1,0,13},
        !           179: {2957,1,0,2}, {2963,1,0,2}, {2969,1,0,3}, {2971,1,0,10}, {2999,1,0,17},
        !           180: {3001,1,0,14}, {3011,1,0,2}, {3019,1,0,2}, {3023,1,0,5}, {3037,1,0,2},
        !           181: {3041,1,0,3}, {3049,1,0,11}, {3061,1,0,6}, {3067,1,0,2}, {3079,1,0,6},
        !           182: {3083,1,0,2}, {3089,1,0,3}, {3109,1,0,6}, {3119,1,0,7}, {3121,1,0,7},
        !           183: {3137,1,0,3}, {3163,1,0,3}, {3167,1,0,5}, {3169,1,0,7}, {3181,1,0,7},
        !           184: {3187,1,0,2}, {3191,1,0,11}, {3203,1,0,2}, {3209,1,0,3}, {3217,1,0,5},
        !           185: {3221,1,0,10}, {3229,1,0,6}, {3251,1,0,6}, {3253,1,0,2}, {3257,1,0,3},
        !           186: {3259,1,0,3}, {3271,1,0,3}, {3299,1,0,2}, {3301,1,0,6}, {3307,1,0,2},
        !           187: {3313,1,0,10}, {3319,1,0,6}, {3323,1,0,2}, {3329,1,0,3}, {3331,1,0,3},
        !           188: {3343,1,0,5}, {3347,1,0,2}, {3359,1,0,11}, {3361,1,0,22}, {3371,1,0,2},
        !           189: {3373,1,0,5}, {3389,1,0,3}, {3391,1,0,3}, {3407,1,0,5}, {3413,1,0,2},
        !           190: {3433,1,0,5}, {3449,1,0,3}, {3457,1,0,7}, {3461,1,0,2}, {3463,1,0,3},
        !           191: {3467,1,0,2}, {3469,1,0,2}, {3491,1,0,2}, {3499,1,0,2}, {3511,1,0,7},
        !           192: {3517,1,0,2}, {3527,1,0,5}, {3529,1,0,17}, {3533,1,0,2}, {3539,1,0,2},
        !           193: {3541,1,0,7}, {3547,1,0,2}, {3557,1,0,2}, {3559,1,0,3}, {3571,1,0,2},
        !           194: {3581,1,0,2}, {3583,1,0,3}, {3593,1,0,3}, {3607,1,0,5}, {3613,1,0,2},
        !           195: {3617,1,0,3}, {3623,1,0,5}, {3631,1,0,15}, {3637,1,0,2}, {3643,1,0,2},
        !           196: {3659,1,0,2}, {3671,1,0,13}, {3673,1,0,5}, {3677,1,0,2}, {3691,1,0,2},
        !           197: {3697,1,0,5}, {3701,1,0,2}, {3709,1,0,2}, {3719,1,0,7}, {3727,1,0,3},
        !           198: {3733,1,0,2}, {3739,1,0,7}, {3761,1,0,3}, {3767,1,0,5}, {3769,1,0,7},
        !           199: {3779,1,0,2}, {3793,1,0,5}, {3797,1,0,2}, {3803,1,0,2}, {3821,1,0,3},
        !           200: {3823,1,0,3}, {3833,1,0,3}, {3847,1,0,5}, {3851,1,0,2}, {3853,1,0,2},
        !           201: {3863,1,0,5}, {3877,1,0,2}, {3881,1,0,13}, {3889,1,0,11}, {3907,1,0,2},
        !           202: {3911,1,0,13}, {3917,1,0,2}, {3919,1,0,3}, {3923,1,0,2}, {3929,1,0,3},
        !           203: {3931,1,0,2}, {3943,1,0,3}, {3947,1,0,2}, {3967,1,0,6}, {3989,1,0,2},
        !           204: {4001,1,0,3}, {4003,1,0,2}, {4007,1,0,5}, {4013,1,0,2}, {4019,1,0,2},
        !           205: {4021,1,0,2}, {4027,1,0,3}, {4049,1,0,3}, {4051,1,0,10}, {4057,1,0,5},
        !           206: {4073,1,0,3}, {4079,1,0,11}, {4091,1,0,2}, {4093,1,0,2}, {4099,1,0,2},
        !           207: {4111,1,0,12}, {4127,1,0,5}, {4129,1,0,13}, {4133,1,0,2}, {4139,1,0,2},
        !           208: {4153,1,0,5}, {4157,1,0,2}, {4159,1,0,3}, {4177,1,0,5}, {4201,1,0,11},
        !           209: {4211,1,0,6}, {4217,1,0,3}, {4219,1,0,2}, {4229,1,0,2}, {4231,1,0,3},
        !           210: {4241,1,0,3}, {4243,1,0,2}, {4253,1,0,2}, {4259,1,0,2}, {4261,1,0,2},
        !           211: {4271,1,0,7}, {4273,1,0,5}, {4283,1,0,2}, {4289,1,0,3}, {4297,1,0,5},
        !           212: {4327,1,0,3}, {4337,1,0,3}, {4339,1,0,10}, {4349,1,0,2}, {4357,1,0,2},
        !           213: {4363,1,0,2}, {4373,1,0,2}, {4391,1,0,14}, {4397,1,0,2}, {4409,1,0,3},
        !           214: {4421,1,0,3}, {4423,1,0,3}, {4441,1,0,21}, {4447,1,0,3}, {4451,1,0,2},
        !           215: {4457,1,0,3}, {4463,1,0,5}, {4481,1,0,3}, {4483,1,0,2}, {4493,1,0,2},
        !           216: {4507,1,0,2}, {4513,1,0,7}, {4517,1,0,2}, {4519,1,0,3}, {4523,1,0,5},
        !           217: {4547,1,0,2}, {4549,1,0,6}, {4561,1,0,11}, {4567,1,0,3}, {4583,1,0,5},
        !           218: {4591,1,0,11}, {4597,1,0,5}, {4603,1,0,2}, {4621,1,0,2}, {4637,1,0,2},
        !           219: {4639,1,0,3}, {4643,1,0,5}, {4649,1,0,3}, {4651,1,0,3}, {4657,1,0,15},
        !           220: {4663,1,0,3}, {4673,1,0,3}, {4679,1,0,11}, {4691,1,0,2}, {4703,1,0,5},
        !           221: {4721,1,0,6}, {4723,1,0,2}, {4729,1,0,17}, {4733,1,0,5}, {4751,1,0,19},
        !           222: {4759,1,0,3}, {4783,1,0,6}, {4787,1,0,2}, {4789,1,0,2}, {4793,1,0,3},
        !           223: {4799,1,0,7}, {4801,1,0,7}, {4813,1,0,2}, {4817,1,0,3}, {4831,1,0,3},
        !           224: {4861,1,0,11}, {4871,1,0,11}, {4877,1,0,2}, {4889,1,0,3}, {4903,1,0,3},
        !           225: {4909,1,0,6}, {4919,1,0,13}, {4931,1,0,6}, {4933,1,0,2}, {4937,1,0,3},
        !           226: {4943,1,0,7}, {4951,1,0,6}, {4957,1,0,2}, {4967,1,0,5}, {4969,1,0,11},
        !           227: {4973,1,0,2}, {4987,1,0,2}, {4993,1,0,5}, {4999,1,0,3}, {5003,1,0,2},
        !           228: {5009,1,0,3}, {5011,1,0,2}, {5021,1,0,3}, {5023,1,0,3}, {5039,1,0,11},
        !           229: {5051,1,0,2}, {5059,1,0,2}, {5077,1,0,2}, {5081,1,0,3}, {5087,1,0,5},
        !           230: {5099,1,0,2}, {5101,1,0,6}, {5107,1,0,2}, {5113,1,0,19}, {5119,1,0,3},
        !           231: {5147,1,0,2}, {5153,1,0,5}, {5167,1,0,6}, {5171,1,0,2}, {5179,1,0,2},
        !           232: {5189,1,0,2}, {5197,1,0,7}, {5209,1,0,17}, {5227,1,0,2}, {5231,1,0,7},
        !           233: {5233,1,0,10}, {5237,1,0,3}, {5261,1,0,2}, {5273,1,0,3}, {5279,1,0,7},
        !           234: {5281,1,0,7}, {5297,1,0,3}, {5303,1,0,5}, {5309,1,0,2}, {5323,1,0,5},
        !           235: {5333,1,0,2}, {5347,1,0,3}, {5351,1,0,11}, {5381,1,0,3}, {5387,1,0,2},
        !           236: {5393,1,0,3}, {5399,1,0,7}, {5407,1,0,3}, {5413,1,0,5}, {5417,1,0,3},
        !           237: {5419,1,0,3}, {5431,1,0,3}, {5437,1,0,5}, {5441,1,0,3}, {5443,1,0,2},
        !           238: {5449,1,0,7}, {5471,1,0,7}, {5477,1,0,2}, {5479,1,0,3}, {5483,1,0,2},
        !           239: {5501,1,0,2}, {5503,1,0,3}, {5507,1,0,2}, {5519,1,0,13}, {5521,1,0,11},
        !           240: {5527,1,0,5}, {5531,1,0,10}, {5557,1,0,2}, {5563,1,0,2}, {5569,1,0,13},
        !           241: {5573,1,0,2}, {5581,1,0,6}, {5591,1,0,11}, {5623,1,0,5}, {5639,1,0,7},
        !           242: {5641,1,0,14}, {5647,1,0,3}, {5651,1,0,2}, {5653,1,0,5}, {5657,1,0,3},
        !           243: {5659,1,0,2}, {5669,1,0,3}, {5683,1,0,2}, {5689,1,0,11}, {5693,1,0,2},
        !           244: {5701,1,0,2}, {5711,1,0,19}, {5717,1,0,2}, {5737,1,0,5}, {5741,1,0,2},
        !           245: {5743,1,0,10}, {5749,1,0,2}, {5779,1,0,2}, {5783,1,0,7}, {5791,1,0,6},
        !           246: {5801,1,0,3}, {5807,1,0,5}, {5813,1,0,2}, {5821,1,0,6}, {5827,1,0,2},
        !           247: {5839,1,0,6}, {5843,1,0,2}, {5849,1,0,3}, {5851,1,0,2}, {5857,1,0,7},
        !           248: {5861,1,0,3}, {5867,1,0,5}, {5869,1,0,2}, {5879,1,0,11}, {5881,1,0,31},
        !           249: {5897,1,0,3}, {5903,1,0,5}, {5923,1,0,2}, {5927,1,0,5}, {5939,1,0,2},
        !           250: {5953,1,0,7}, {5981,1,0,3}, {5987,1,0,2}, {6007,1,0,3}, {6011,1,0,2},
        !           251: {6029,1,0,2}, {6037,1,0,5}, {6043,1,0,5}, {6047,1,0,5}, {6053,1,0,2},
        !           252: {6067,1,0,2}, {6073,1,0,10}, {6079,1,0,17}, {6089,1,0,3}, {6091,1,0,7},
        !           253: {6101,1,0,2}, {6113,1,0,3}, {6121,1,0,7}, {6131,1,0,2}, {6133,1,0,5},
        !           254: {6143,1,0,5}, {6151,1,0,3}, {6163,1,0,3}, {6173,1,0,2}, {6197,1,0,2},
        !           255: {6199,1,0,3}, {6203,1,0,2}, {6211,1,0,2}, {6217,1,0,5}, {6221,1,0,3},
        !           256: {6229,1,0,2}, {6247,1,0,5}, {6257,1,0,3}, {6263,1,0,5}, {6269,1,0,2},
        !           257: {6271,1,0,11}, {6277,1,0,2}, {6287,1,0,7}, {6299,1,0,2}, {6301,1,0,10},
        !           258: {6311,1,0,7}, {6317,1,0,2}, {6323,1,0,2}, {6329,1,0,3}, {6337,1,0,10},
        !           259: {6343,1,0,3}, {6353,1,0,3}, {6359,1,0,13}, {6361,1,0,19}, {6367,1,0,3},
        !           260: {6373,1,0,2}, {6379,1,0,2}, {6389,1,0,2}, {6397,1,0,2}, {6421,1,0,6},
        !           261: {6427,1,0,3}, {6449,1,0,3}, {6451,1,0,3}, {6469,1,0,2}, {6473,1,0,3},
        !           262: {6481,1,0,7}, {6491,1,0,2}, {6521,1,0,6}, {6529,1,0,7}, {6547,1,0,2},
        !           263: {6551,1,0,17}, {6553,1,0,10}, {6563,1,0,5}, {6569,1,0,3}, {6571,1,0,3},
        !           264: {6577,1,0,5}, {6581,1,0,14}, {6599,1,0,13}, {6607,1,0,3}, {6619,1,0,2},
        !           265: {6637,1,0,2}, {6653,1,0,2}, {6659,1,0,2}, {6661,1,0,6}, {6673,1,0,5},
        !           266: {6679,1,0,7}, {6689,1,0,3}, {6691,1,0,2}, {6701,1,0,2}, {6703,1,0,5},
        !           267: {6709,1,0,2}, {6719,1,0,11}, {6733,1,0,2}, {6737,1,0,3}, {6761,1,0,3},
        !           268: {6763,1,0,2}, {6779,1,0,2}, {6781,1,0,2}, {6791,1,0,7}, {6793,1,0,10},
        !           269: {6803,1,0,2}, {6823,1,0,3}, {6827,1,0,2}, {6829,1,0,2}, {6833,1,0,3},
        !           270: {6841,1,0,22}, {6857,1,0,3}, {6863,1,0,5}, {6869,1,0,2}, {6871,1,0,3},
        !           271: {6883,1,0,2}, {6899,1,0,2}, {6907,1,0,2}, {6911,1,0,7}, {6917,1,0,2},
        !           272: {6947,1,0,2}, {6949,1,0,2}, {6959,1,0,7}, {6961,1,0,13}, {6967,1,0,5},
        !           273: {6971,1,0,2}, {6977,1,0,3}, {6983,1,0,5}, {6991,1,0,6}, {6997,1,0,5},
        !           274: {7001,1,0,3}, {7013,1,0,2}, {7019,1,0,2}, {7027,1,0,2}, {7039,1,0,3},
        !           275: {7043,1,0,2}, {7057,1,0,5}, {7069,1,0,2}, {7079,1,0,7}, {7103,1,0,5},
        !           276: {7109,1,0,2}, {7121,1,0,3}, {7127,1,0,5}, {7129,1,0,7}, {7151,1,0,7},
        !           277: {7159,1,0,3}, {7177,1,0,10}, {7187,1,0,2}, {7193,1,0,3}, {7207,1,0,3},
        !           278: {7211,1,0,2}, {7213,1,0,5}, {7219,1,0,2}, {7229,1,0,2}, {7237,1,0,2},
        !           279: {7243,1,0,2}, {7247,1,0,5}, {7253,1,0,2}, {7283,1,0,2}, {7297,1,0,5},
        !           280: {7307,1,0,2}, {7309,1,0,6}, {7321,1,0,7}, {7331,1,0,2}, {7333,1,0,6},
        !           281: {7349,1,0,2}, {7351,1,0,6}, {7369,1,0,7}, {7393,1,0,5}, {7411,1,0,2},
        !           282: {7417,1,0,5}, {7433,1,0,3}, {7451,1,0,2}, {7457,1,0,3}, {7459,1,0,2},
        !           283: {7477,1,0,2}, {7481,1,0,6}, {7487,1,0,5}, {7489,1,0,7}, {7499,1,0,2},
        !           284: {7507,1,0,2}, {7517,1,0,2}, {7523,1,0,2}, {7529,1,0,3}, {7537,1,0,7},
        !           285: {7541,1,0,2}, {7547,1,0,2}, {7549,1,0,2}, {7559,1,0,13}, {7561,1,0,13},
        !           286: {7573,1,0,2}, {7577,1,0,3}, {7583,1,0,5}, {7589,1,0,2}, {7591,1,0,6},
        !           287: {7603,1,0,2}, {7607,1,0,5}, {7621,1,0,2}, {7639,1,0,7}, {7643,1,0,2},
        !           288: {7649,1,0,3}, {7669,1,0,2}, {7673,1,0,3}, {7681,1,0,17}, {7687,1,0,6},
        !           289: {7691,1,0,2}, {7699,1,0,3}, {7703,1,0,5}, {7717,1,0,2}, {7723,1,0,3},
        !           290: {7727,1,0,5}, {7741,1,0,7}, {7753,1,0,10}, {7757,1,0,2}, {7759,1,0,3},
        !           291: {7789,1,0,2}, {7793,1,0,3}, {7817,1,0,3}, {7823,1,0,5}, {7829,1,0,2},
        !           292: {7841,1,0,12}, {7853,1,0,2}, {7867,1,0,3}, {7873,1,0,5}, {7877,1,0,2},
        !           293: {7879,1,0,3}, {7883,1,0,2}, {7901,1,0,2}, {7907,1,0,2}, {7919,1,0,7},
        !           294: {7927,1,0,3}, {7933,1,0,2}, {7937,1,0,3}, {7949,1,0,2}, {7951,1,0,6},
        !           295: {7963,1,0,5}, {7993,1,0,5}, {8009,1,0,3}, {8011,1,0,14}, {8017,1,0,5},
        !           296: {8039,1,0,11}, {8053,1,0,2}, {8059,1,0,3}, {8069,1,0,2}, {8081,1,0,3},
        !           297: {8087,1,0,5}, {8089,1,0,17}, {8093,1,0,2}, {8101,1,0,6}, {8111,1,0,11},
        !           298: {8117,1,0,2}, {8123,1,0,2}, {8147,1,0,2}, {8161,1,0,7}, {8167,1,0,3},
        !           299: {8171,1,0,2}, {8179,1,0,2}, {8191,1,0,17}, {8209,1,0,7}, {8219,1,0,2},
        !           300: {8221,1,0,2}, {8231,1,0,11}, {8233,1,0,10}, {8237,1,0,2}, {8243,1,0,2},
        !           301: {8263,1,0,3}, {8269,1,0,2}, {8273,1,0,3}, {8287,1,0,3}, {8291,1,0,2},
        !           302: {8293,1,0,2}, {8297,1,0,3}, {8311,1,0,3}, {8317,1,0,6}, {8329,1,0,7},
        !           303: {8353,1,0,5}, {8363,1,0,2}, {8369,1,0,3}, {8377,1,0,5}, {8387,1,0,2},
        !           304: {8389,1,0,6}, {8419,1,0,3}, {8423,1,0,5}, {8429,1,0,2}, {8431,1,0,3},
        !           305: {8443,1,0,2}, {8447,1,0,5}, {8461,1,0,6}, {8467,1,0,2}, {8501,1,0,7},
        !           306: {8513,1,0,5}, {8521,1,0,13}, {8527,1,0,5}, {8537,1,0,3}, {8539,1,0,2},
        !           307: {8543,1,0,5}, {8563,1,0,2}, {8573,1,0,2}, {8581,1,0,6}, {8597,1,0,2},
        !           308: {8599,1,0,3}, {8609,1,0,3}, {8623,1,0,3}, {8627,1,0,2}, {8629,1,0,6},
        !           309: {8641,1,0,17}, {8647,1,0,3}, {8663,1,0,5}, {8669,1,0,2}, {8677,1,0,2},
        !           310: {8681,1,0,15}, {8689,1,0,13}, {8693,1,0,2}, {8699,1,0,2}, {8707,1,0,5},
        !           311: {8713,1,0,5}, {8719,1,0,3}, {8731,1,0,2}, {8737,1,0,5}, {8741,1,0,2},
        !           312: {8747,1,0,2}, {8753,1,0,3}, {8761,1,0,23}, {8779,1,0,11}, {8783,1,0,5},
        !           313: {8803,1,0,2}, {8807,1,0,5}, {8819,1,0,2}, {8821,1,0,2}, {8831,1,0,7},
        !           314: {8837,1,0,2}, {8839,1,0,3}, {8849,1,0,3}, {8861,1,0,2}, {8863,1,0,3},
        !           315: {8867,1,0,2}, {8887,1,0,3}, {8893,1,0,5}, {8923,1,0,2}, {8929,1,0,11},
        !           316: {8933,1,0,2}, {8941,1,0,6}, {8951,1,0,13}, {8963,1,0,2}, {8969,1,0,3},
        !           317: {8971,1,0,2}, {8999,1,0,7}, {9001,1,0,7}, {9007,1,0,3}, {9011,1,0,2},
        !           318: {9013,1,0,5}, {9029,1,0,2}, {9041,1,0,3}, {9043,1,0,3}, {9049,1,0,7},
        !           319: {9059,1,0,2}, {9067,1,0,3}, {9091,1,0,3}, {9103,1,0,6}, {9109,1,0,10},
        !           320: {9127,1,0,3}, {9133,1,0,6}, {9137,1,0,3}, {9151,1,0,3}, {9157,1,0,6},
        !           321: {9161,1,0,3}, {9173,1,0,2}, {9181,1,0,2}, {9187,1,0,3}, {9199,1,0,3},
        !           322: {9203,1,0,2}, {9209,1,0,3}, {9221,1,0,2}, {9227,1,0,2}, {9239,1,0,19},
        !           323: {9241,1,0,13}, {9257,1,0,3}, {9277,1,0,5}, {9281,1,0,3}, {9283,1,0,2},
        !           324: {9293,1,0,2}, {9311,1,0,7}, {9319,1,0,3}, {9323,1,0,2}, {9337,1,0,5},
        !           325: {9341,1,0,2}, {9343,1,0,5}, {9349,1,0,2}, {9371,1,0,2}, {9377,1,0,3},
        !           326: {9391,1,0,3}, {9397,1,0,2}, {9403,1,0,3}, {9413,1,0,3}, {9419,1,0,2},
        !           327: {9421,1,0,2}, {9431,1,0,7}, {9433,1,0,5}, {9437,1,0,2}, {9439,1,0,22},
        !           328: {9461,1,0,3}, {9463,1,0,3}, {9467,1,0,2}, {9473,1,0,3}, {9479,1,0,7},
        !           329: {9491,1,0,2}, {9497,1,0,3}, {9511,1,0,3}, {9521,1,0,3}, {9533,1,0,2},
        !           330: {9539,1,0,2}, {9547,1,0,2}, {9551,1,0,11}, {9587,1,0,2}, {9601,1,0,13},
        !           331: {9613,1,0,2}, {9619,1,0,2}, {9623,1,0,5}, {9629,1,0,2}, {9631,1,0,3},
        !           332: {9643,1,0,2}, {9649,1,0,7}, {9661,1,0,2}, {9677,1,0,2}, {9679,1,0,3},
        !           333: {9689,1,0,3}, {9697,1,0,10}, {9719,1,0,17}, {9721,1,0,7}, {9733,1,0,2},
        !           334: {9739,1,0,3}, {9743,1,0,5}, {9749,1,0,2}, {9767,1,0,5}, {9769,1,0,13},
        !           335: {9781,1,0,6}, {9787,1,0,3}, {9791,1,0,11}, {9803,1,0,2}, {9811,1,0,3},
        !           336: {9817,1,0,5}, {9829,1,0,10}, {9833,1,0,3}, {9839,1,0,7}, {9851,1,0,2},
        !           337: {9857,1,0,5}, {9859,1,0,2}, {9871,1,0,3}, {9883,1,0,2}, {9887,1,0,5},
        !           338: {9901,1,0,2}, {9907,1,0,2}, {9923,1,0,2}, {9929,1,0,3}, {9931,1,0,10},
        !           339: {9941,1,0,2}, {9949,1,0,2}, {9967,1,0,3}, {9973,1,0,11}, {10007,1,0,5},
        !           340: {10009,1,0,11}, {10037,1,0,2}, {10039,1,0,3}, {10061,1,0,3}, {10067,1,0,2},
        !           341: {10069,1,0,2}, {10079,1,0,11}, {10091,1,0,2}, {10093,1,0,2}, {10099,1,0,2},
        !           342: {10103,1,0,5}, {10111,1,0,12}, {10133,1,0,2}, {10139,1,0,2}, {10141,1,0,2},
        !           343: {10151,1,0,7}, {10159,1,0,3}, {10163,1,0,2}, {10169,1,0,3}, {10177,1,0,7},
        !           344: {10181,1,0,2}, {10193,1,0,3}, {10211,1,0,6}, {10223,1,0,5}, {10243,1,0,7},
        !           345: {10247,1,0,5}, {10253,1,0,2}, {10259,1,0,2}, {10267,1,0,2}, {10271,1,0,7},
        !           346: {10273,1,0,10}, {10289,1,0,3}, {10301,1,0,2}, {10303,1,0,3}, {10313,1,0,3},
        !           347: {10321,1,0,7}, {10331,1,0,2}, {10333,1,0,5}, {10337,1,0,3}, {10343,1,0,5},
        !           348: {10357,1,0,2}, {10369,1,0,13}, {10391,1,0,19}, {10399,1,0,6}, {10427,1,0,2},
        !           349: {10429,1,0,7}, {10433,1,0,3}, {10453,1,0,5}, {10457,1,0,3}, {10459,1,0,2},
        !           350: {10463,1,0,5}, {10477,1,0,2}, {10487,1,0,5}, {10499,1,0,2}, {10501,1,0,2},
        !           351: {10513,1,0,7}, {10529,1,0,3}, {10531,1,0,3}, {10559,1,0,23}, {10567,1,0,6},
        !           352: {10589,1,0,2}, {10597,1,0,5}, {10601,1,0,3}, {10607,1,0,5}, {10613,1,0,2},
        !           353: {10627,1,0,5}, {10631,1,0,11}, {10639,1,0,6}, {10651,1,0,7}, {10657,1,0,7},
        !           354: {10663,1,0,3}, {10667,1,0,2}, {10687,1,0,5}, {10691,1,0,2}, {10709,1,0,2},
        !           355: {10711,1,0,3}, {10723,1,0,2}, {10729,1,0,7}, {10733,1,0,2}, {10739,1,0,6},
        !           356: {10753,1,0,11}, {10771,1,0,3}, {10781,1,0,10}, {10789,1,0,2}, {10799,1,0,19},
        !           357: {10831,1,0,7}, {10837,1,0,2}, {10847,1,0,5}, {10853,1,0,2}, {10859,1,0,2},
        !           358: {10861,1,0,2}, {10867,1,0,2}, {10883,1,0,2}, {10889,1,0,3}, {10891,1,0,2},
        !           359: {10903,1,0,3}, {10909,1,0,2}, {10937,1,0,3}, {10939,1,0,3}, {10949,1,0,2},
        !           360: {10957,1,0,5}, {10973,1,0,2}, {10979,1,0,2}, {10987,1,0,2}, {10993,1,0,7},
        !           361: {11003,1,0,2}, {11027,1,0,2}, {11047,1,0,3}, {11057,1,0,3}, {11059,1,0,10},
        !           362: {11069,1,0,2}, {11071,1,0,3}, {11083,1,0,2}, {11087,1,0,5}, {11093,1,0,2},
        !           363: {11113,1,0,13}, {11117,1,0,3}, {11119,1,0,3}, {11131,1,0,2}, {11149,1,0,10},
        !           364: {11159,1,0,7}, {11161,1,0,7}, {11171,1,0,2}, {11173,1,0,5}, {11177,1,0,3},
        !           365: {11197,1,0,2}, {11213,1,0,2}, {11239,1,0,3}, {11243,1,0,5}, {11251,1,0,13},
        !           366: {11257,1,0,10}, {11261,1,0,2}, {11273,1,0,3}, {11279,1,0,7}, {11287,1,0,3},
        !           367: {11299,1,0,3}, {11311,1,0,3}, {11317,1,0,2}, {11321,1,0,3}, {11329,1,0,7},
        !           368: {11351,1,0,7}, {11353,1,0,7}, {11369,1,0,3}, {11383,1,0,5}, {11393,1,0,3},
        !           369: {11399,1,0,11}, {11411,1,0,7}, {11423,1,0,5}, {11437,1,0,2}, {11443,1,0,2},
        !           370: {11447,1,0,5}, {11467,1,0,5}, {11471,1,0,11}, {11483,1,0,2}, {11489,1,0,3},
        !           371: {11491,1,0,3}, {11497,1,0,7}, {11503,1,0,3}, {11519,1,0,7}, {11527,1,0,5},
        !           372: {11549,1,0,2}, {11551,1,0,7}, {11579,1,0,2}, {11587,1,0,2}, {11593,1,0,5},
        !           373: {11597,1,0,3}, {11617,1,0,10}, {11621,1,0,2}, {11633,1,0,3}, {11657,1,0,3},
        !           374: {11677,1,0,2}, {11681,1,0,3}, {11689,1,0,7}, {11699,1,0,2}, {11701,1,0,6},
        !           375: {11717,1,0,2}, {11719,1,0,6}, {11731,1,0,3}, {11743,1,0,3}, {11777,1,0,3},
        !           376: {11779,1,0,2}, {11783,1,0,5}, {11789,1,0,2}, {11801,1,0,3}, {11807,1,0,5},
        !           377: {11813,1,0,2}, {11821,1,0,2}, {11827,1,0,2}, {11831,1,0,7}, {11833,1,0,5},
        !           378: {11839,1,0,3}, {11863,1,0,3}, {11867,1,0,2}, {11887,1,0,3}, {11897,1,0,3},
        !           379: {11903,1,0,5}, {11909,1,0,2}, {11923,1,0,5}, {11927,1,0,5}, {11933,1,0,2},
        !           380: {11939,1,0,2}, {11941,1,0,10}, {11953,1,0,5}, {11959,1,0,3}, {11969,1,0,3},
        !           381: {11971,1,0,10}, {11981,1,0,2}, {11987,1,0,2}, {12007,1,0,13}, {12011,1,0,2},
        !           382: {12037,1,0,5}, {12041,1,0,3}, {12043,1,0,2}, {12049,1,0,13}, {12071,1,0,11},
        !           383: {12073,1,0,7}, {12097,1,0,5}, {12101,1,0,3}, {12107,1,0,2}, {12109,1,0,6},
        !           384: {12113,1,0,3}, {12119,1,0,7}, {12143,1,0,10}, {12149,1,0,2}, {12157,1,0,2},
        !           385: {12161,1,0,3}, {12163,1,0,5}, {12197,1,0,2}, {12203,1,0,2}, {12211,1,0,2},
        !           386: {12227,1,0,2}, {12239,1,0,13}, {12241,1,0,7}, {12251,1,0,2}, {12253,1,0,2},
        !           387: {12263,1,0,5}, {12269,1,0,2}, {12277,1,0,2}, {12281,1,0,3}, {12289,1,0,11},
        !           388: {12301,1,0,2}, {12323,1,0,2}, {12329,1,0,3}, {12343,1,0,7}, {12347,1,0,2},
        !           389: {12373,1,0,2}, {12377,1,0,6}, {12379,1,0,2}, {12391,1,0,26}, {12401,1,0,3},
        !           390: {12409,1,0,7}, {12413,1,0,2}, {12421,1,0,7}, {12433,1,0,13}, {12437,1,0,2},
        !           391: {12451,1,0,3}, {12457,1,0,10}, {12473,1,0,3}, {12479,1,0,23}, {12487,1,0,3},
        !           392: {12491,1,0,2}, {12497,1,0,3}, {12503,1,0,5}, {12511,1,0,3}, {12517,1,0,6},
        !           393: {12527,1,0,5}, {12539,1,0,2}, {12541,1,0,14}, {12547,1,0,2}, {12553,1,0,5},
        !           394: {12569,1,0,3}, {12577,1,0,10}, {12583,1,0,5}, {12589,1,0,2}, {12601,1,0,11},
        !           395: {12611,1,0,2}, {12613,1,0,2}, {12619,1,0,2}, {12637,1,0,2}, {12641,1,0,3},
        !           396: {12647,1,0,5}, {12653,1,0,2}, {12659,1,0,2}, {12671,1,0,14}, {12689,1,0,3},
        !           397: {12697,1,0,7}, {12703,1,0,3}, {12713,1,0,3}, {12721,1,0,13}, {12739,1,0,2},
        !           398: {12743,1,0,5}, {12757,1,0,2}, {12763,1,0,2}, {12781,1,0,2}, {12791,1,0,7},
        !           399: {12799,1,0,13}, {12809,1,0,3}, {12821,1,0,2}, {12823,1,0,3}, {12829,1,0,2},
        !           400: {12841,1,0,21}, {12853,1,0,5}, {12889,1,0,13}, {12893,1,0,3}, {12899,1,0,2},
        !           401: {12907,1,0,2}, {12911,1,0,23}, {12917,1,0,2}, {12919,1,0,6}, {12923,1,0,2},
        !           402: {12941,1,0,2}, {12953,1,0,3}, {12959,1,0,7}, {12967,1,0,3}, {12973,1,0,14},
        !           403: {12979,1,0,2}, {12983,1,0,5}, {13001,1,0,3}, {13003,1,0,5}, {13007,1,0,5},
        !           404: {13009,1,0,7}, {13033,1,0,5}, {13037,1,0,2}, {13043,1,0,2}, {13049,1,0,3},
        !           405: {13063,1,0,5}, {13093,1,0,6}, {13099,1,0,3}, {13103,1,0,5}, {13109,1,0,2},
        !           406: {13121,1,0,7}, {13127,1,0,5}, {13147,1,0,2}, {13151,1,0,13}, {13159,1,0,3},
        !           407: {13163,1,0,2}, {13171,1,0,11}, {13177,1,0,5}, {13183,1,0,3}, {13187,1,0,2},
        !           408: {13217,1,0,3}, {13219,1,0,3}, {13229,1,0,2}, {13241,1,0,3}, {13249,1,0,7},
        !           409: {13259,1,0,6}, {13267,1,0,3}, {13291,1,0,2}, {13297,1,0,5}, {13309,1,0,6},
        !           410: {13313,1,0,3}, {13327,1,0,3}, {13331,1,0,2}, {13337,1,0,3}, {13339,1,0,2},
        !           411: {13367,1,0,5}, {13381,1,0,10}, {13397,1,0,2}, {13399,1,0,3}, {13411,1,0,2},
        !           412: {13417,1,0,5}, {13421,1,0,10}, {13441,1,0,11}, {13451,1,0,2}, {13457,1,0,3},
        !           413: {13463,1,0,5}, {13469,1,0,2}, {13477,1,0,2}, {13487,1,0,5}, {13499,1,0,6},
        !           414: {13513,1,0,5}, {13523,1,0,2}, {13537,1,0,7}, {13553,1,0,3}, {13567,1,0,3},
        !           415: {13577,1,0,3}, {13591,1,0,3}, {13597,1,0,5}, {13613,1,0,2}, {13619,1,0,2},
        !           416: {13627,1,0,2}, {13633,1,0,5}, {13649,1,0,3}, {13669,1,0,6}, {13679,1,0,7},
        !           417: {13681,1,0,22}, {13687,1,0,3}, {13691,1,0,2}, {13693,1,0,6}, {13697,1,0,3},
        !           418: {13709,1,0,2}, {13711,1,0,6}, {13721,1,0,3}, {13723,1,0,2}, {13729,1,0,23},
        !           419: {13751,1,0,11}, {13757,1,0,2}, {13759,1,0,6}, {13763,1,0,2}, {13781,1,0,7},
        !           420: {13789,1,0,7}, {13799,1,0,7}, {13807,1,0,5}, {13829,1,0,2}, {13831,1,0,6},
        !           421: {13841,1,0,6}, {13859,1,0,2}, {13873,1,0,5}, {13877,1,0,2}, {13879,1,0,6},
        !           422: {13883,1,0,2}, {13901,1,0,2}, {13903,1,0,3}, {13907,1,0,2}, {13913,1,0,3},
        !           423: {13921,1,0,7}, {13931,1,0,2}, {13933,1,0,2}, {13963,1,0,3}, {13967,1,0,5},
        !           424: {13997,1,0,2}, {13999,1,0,3}, {14009,1,0,3}, {14011,1,0,2}, {14029,1,0,6},
        !           425: {14033,1,0,3}, {14051,1,0,2}, {14057,1,0,3}, {14071,1,0,7}, {14081,1,0,3},
        !           426: {14083,1,0,3}, {14087,1,0,5}, {14107,1,0,2}, {14143,1,0,3}, {14149,1,0,6},
        !           427: {14153,1,0,3}, {14159,1,0,13}, {14173,1,0,2}, {14177,1,0,3}, {14197,1,0,11},
        !           428: {14207,1,0,5}, {14221,1,0,2}, {14243,1,0,2}, {14249,1,0,3}, {14251,1,0,3},
        !           429: {14281,1,0,19}, {14293,1,0,6}, {14303,1,0,5}, {14321,1,0,3}, {14323,1,0,5},
        !           430: {14327,1,0,5}, {14341,1,0,2}, {14347,1,0,3}, {14369,1,0,3}, {14387,1,0,2},
        !           431: {14389,1,0,2}, {14401,1,0,11}, {14407,1,0,19}, {14411,1,0,2}, {14419,1,0,2},
        !           432: {14423,1,0,5}, {14431,1,0,3}, {14437,1,0,5}, {14447,1,0,5}, {14449,1,0,22},
        !           433: {14461,1,0,2}, {14479,1,0,3}, {14489,1,0,3}, {14503,1,0,3}, {14519,1,0,13},
        !           434: {14533,1,0,2}, {14537,1,0,3}, {14543,1,0,5}, {14549,1,0,2}, {14551,1,0,3},
        !           435: {14557,1,0,2}, {14561,1,0,6}, {14563,1,0,3}, {14591,1,0,11}, {14593,1,0,5},
        !           436: {14621,1,0,2}, {14627,1,0,2}, {14629,1,0,2}, {14633,1,0,3}, {14639,1,0,11},
        !           437: {14653,1,0,2}, {14657,1,0,3}, {14669,1,0,2}, {14683,1,0,3}, {14699,1,0,2},
        !           438: {14713,1,0,5}, {14717,1,0,2}, {14723,1,0,2}, {14731,1,0,10}, {14737,1,0,10},
        !           439: {14741,1,0,2}, {14747,1,0,2}, {14753,1,0,3}, {14759,1,0,17}, {14767,1,0,3},
        !           440: {14771,1,0,2}, {14779,1,0,3}, {14783,1,0,5}, {14797,1,0,2}, {14813,1,0,2},
        !           441: {14821,1,0,2}, {14827,1,0,2}, {14831,1,0,11}, {14843,1,0,2}, {14851,1,0,2},
        !           442: {14867,1,0,2}, {14869,1,0,2}, {14879,1,0,7}, {14887,1,0,3}, {14891,1,0,2},
        !           443: {14897,1,0,3}, {14923,1,0,2}, {14929,1,0,7}, {14939,1,0,2}, {14947,1,0,2},
        !           444: {14951,1,0,19}, {14957,1,0,2}, {14969,1,0,3}, {14983,1,0,3}, {15013,1,0,2},
        !           445: {15017,1,0,3}, {15031,1,0,3}, {15053,1,0,2}, {15061,1,0,2}, {15073,1,0,5},
        !           446: {15077,1,0,2}, {15083,1,0,2}, {15091,1,0,2}, {15101,1,0,2}, {15107,1,0,2},
        !           447: {15121,1,0,11}, {15131,1,0,2}, {15137,1,0,3}, {15139,1,0,2}, {15149,1,0,2},
        !           448: {15161,1,0,3}, {15173,1,0,2}, {15187,1,0,2}, {15193,1,0,5}, {15199,1,0,6},
        !           449: {15217,1,0,10}, {15227,1,0,2}, {15233,1,0,3}, {15241,1,0,11}, {15259,1,0,2},
        !           450: {15263,1,0,5}, {15269,1,0,2}, {15271,1,0,11}, {15277,1,0,6}, {15287,1,0,5},
        !           451: {15289,1,0,11}, {15299,1,0,2}, {15307,1,0,3}, {15313,1,0,5}, {15319,1,0,3},
        !           452: {15329,1,0,3}, {15331,1,0,2}, {15349,1,0,2}, {15359,1,0,11}, {15361,1,0,7},
        !           453: {15373,1,0,2}, {15377,1,0,3}, {15383,1,0,5}, {15391,1,0,12}, {15401,1,0,6},
        !           454: {15413,1,0,2}, {15427,1,0,2}, {15439,1,0,3}, {15443,1,0,2}, {15451,1,0,3},
        !           455: {15461,1,0,2}, {15467,1,0,5}, {15473,1,0,3}, {15493,1,0,5}, {15497,1,0,3},
        !           456: {15511,1,0,3}, {15527,1,0,5}, {15541,1,0,6}, {15551,1,0,7}, {15559,1,0,3},
        !           457: {15569,1,0,3}, {15581,1,0,2}, {15583,1,0,5}, {15601,1,0,23}, {15607,1,0,3},
        !           458: {15619,1,0,7}, {15629,1,0,2}, {15641,1,0,3}, {15643,1,0,5}, {15647,1,0,5},
        !           459: {15649,1,0,11}, {15661,1,0,2}, {15667,1,0,2}, {15671,1,0,13}, {15679,1,0,11},
        !           460: {15683,1,0,2}, {15727,1,0,3}, {15731,1,0,2}, {15733,1,0,6}, {15737,1,0,3},
        !           461: {15739,1,0,2}, {15749,1,0,2}, {15761,1,0,3}, {15767,1,0,5}, {15773,1,0,2},
        !           462: {15787,1,0,2}, {15791,1,0,29}, {15797,1,0,2}, {15803,1,0,2}, {15809,1,0,3},
        !           463: {15817,1,0,5}, {15823,1,0,3}, {15859,1,0,2}, {15877,1,0,5}, {15881,1,0,3},
        !           464: {15887,1,0,5}, {15889,1,0,21}, {15901,1,0,10}, {15907,1,0,2}, {15913,1,0,5},
        !           465: {15919,1,0,6}, {15923,1,0,2}, {15937,1,0,7}, {15959,1,0,11}, {15971,1,0,2},
        !           466: {15973,1,0,7}, {15991,1,0,12}, {16001,1,0,3}, {16007,1,0,5}, {16033,1,0,5},
        !           467: {16057,1,0,7}, {16061,1,0,12}, {16063,1,0,5}, {16067,1,0,2}, {16069,1,0,2},
        !           468: {16073,1,0,3}, {16087,1,0,5}, {16091,1,0,6}, {16097,1,0,3}, {16103,1,0,5},
        !           469: {16111,1,0,7}, {16127,1,0,5}, {16139,1,0,2}, {16141,1,0,6}, {16183,1,0,3},
        !           470: {16187,1,0,2}, {16189,1,0,2}, {16193,1,0,5}, {16217,1,0,3}, {16223,1,0,5},
        !           471: {16229,1,0,2}, {16231,1,0,3}, {16249,1,0,17}, {16253,1,0,2}, {16267,1,0,3},
        !           472: {16273,1,0,7}, {16301,1,0,2}, {16319,1,0,7}, {16333,1,0,2}, {16339,1,0,2},
        !           473: {16349,1,0,2}, {16361,1,0,3}, {16363,1,0,2}, {16369,1,0,7}, {16381,1,0,2},
        !           474: };
        !           475:
1.2       noro      476: void dec_um(p,a,u)
                    477: int p,a;
                    478: UM u;
                    479: {
                    480:        int i;
                    481:
                    482:        for ( i = 0; a; i++, a /= p )
                    483:                COEF(u)[i] = a%p;
                    484:        DEG(u) = i-1;
                    485: }
1.1       noro      486:
                    487: /*
1.2       noro      488:  * an element of GF(p^n) f(x)=a(n-1)*x^(n-1)+...+a(0)
                    489:  * is encodeded to f(p).
1.1       noro      490:  * current_gfs_iton[i] = r^i mod p (i=0,...,p-2)
                    491:  * current_gfs_iton[p-1] = 0
                    492:  */
                    493:
                    494: void setmod_sf(p,n)
                    495: int p,n;
                    496: {
1.2       noro      497:        int r,i,q1,q,t,t1;
                    498:        UM dp;
1.1       noro      499:
1.2       noro      500:        for ( i = 0, q = 1; i < n; i++ )
                    501:                q *= p;
                    502:        dp = UMALLOC(n);
1.6     ! noro      503:        r = search_defpoly_and_primitive_root(p,n,dp);
        !           504:        if ( !r ) {
        !           505:                generate_defpoly_um(p,n,dp);
        !           506:                r = generate_primitive_root_enc(p,n,dp);
        !           507:        }
1.2       noro      508:        current_gfs_p = p;
                    509:        current_gfs_q = q;
                    510:        current_gfs_q1 = q1 = q-1;
1.1       noro      511:        if ( n > 1 )
1.2       noro      512:                umtop(CO->v,dp,&current_gfs_ext);
                    513:        else
                    514:                current_gfs_ext = 0;
                    515:        current_gfs_iton = (int *)MALLOC(q1*sizeof(int));
                    516:        current_gfs_iton[0] = 1;
                    517:        for ( i = 1; i < q1; i++ )
                    518:                current_gfs_iton[i] = mulremum_enc(p,n,dp,current_gfs_iton[i-1],r);
                    519:
                    520:        current_gfs_ntoi = (int *)MALLOC(q*sizeof(int));
                    521:        current_gfs_ntoi[0] = -1;
                    522:        for ( i = 0; i < q1; i++ )
                    523:                current_gfs_ntoi[current_gfs_iton[i]] = i;
                    524:
                    525:        current_gfs_plus1 = (int *)MALLOC(q*sizeof(int));
                    526:        for ( i = 0; i < q1; i++ ) {
                    527:                t = current_gfs_iton[i];
                    528:                /* add 1 to the constant part */
                    529:                t1 = (t/p)*p+((t+1)%p);
                    530:                current_gfs_plus1[i] = current_gfs_ntoi[t1];
1.1       noro      531:        }
                    532: }
                    533:
1.6     ! noro      534: int search_defpoly_and_primitive_root(p,n,dp)
        !           535: int p,n;
        !           536: UM dp;
        !           537: {
        !           538:        int l,min,max,mid,p1,i,ind,t;
        !           539:
        !           540:        l = sizeof(prim_root_info_tab)/sizeof(struct prim_root_info);
        !           541:        min = 0; max = l-1;
        !           542:        ind = -1;
        !           543:        while ( max - min > 1 ) {
        !           544:                mid = (max+min)/2;
        !           545:                p1 = prim_root_info_tab[mid].p;
        !           546:                if ( p1 == p ) {
        !           547:                        ind = mid; break;
        !           548:                } else if ( p1 > p )
        !           549:                        max = mid;
        !           550:                else
        !           551:                        min = mid;
        !           552:        }
        !           553:        if ( ind < 0 ) {
        !           554:                if ( prim_root_info_tab[min].p == p )
        !           555:                        ind = min;
        !           556:                else if ( prim_root_info_tab[max].p == p )
        !           557:                        ind = max;
        !           558:                else
        !           559:                        return 0; /* XXX */
        !           560:        }
        !           561:        /* now prim_root_info_tab[ind].p = p */
        !           562:        t = ind - (prim_root_info_tab[ind].extdeg-1);
        !           563:        /* now prim_root_info_tab[t].extdeg = 1 */
        !           564:        for ( i = t; prim_root_info_tab[i].p == p; i++ )
        !           565:                if ( prim_root_info_tab[i].extdeg == n )
        !           566:                        break;
        !           567:        if ( prim_root_info_tab[i].p != p )
        !           568:                return 0;
        !           569:        dec_um(p,prim_root_info_tab[i].defpoly,dp);
        !           570:        return prim_root_info_tab[i].prim_root;
        !           571: }
        !           572:
1.2       noro      573: void generate_defpoly_um(p,n,dp)
                    574: int p,n;
                    575: UM dp;
1.1       noro      576: {
1.2       noro      577:        int i,j,a,c,q;
                    578:        UM wf,wdf,wgcd;
1.1       noro      579:
1.2       noro      580:        wf = W_UMALLOC(n);
                    581:        wdf = W_UMALLOC(n);
                    582:        wgcd = W_UMALLOC(n);
                    583:        COEF(dp)[n] = 1;
                    584:        DEG(dp) = n;
                    585:        for ( i = 0, q = 1; i < n; i++ )
                    586:                q *= p;
                    587:        for ( i = 0; i < q; i++ ) {
                    588:                for ( j = 0, a = i; a; j++, a /= p )
                    589:                        COEF(dp)[j] = a%p;
                    590:                for ( ; j < n; j++ )
                    591:                        COEF(dp)[j] = 0;
                    592:                cpyum(dp,wf);
                    593:                diffum(p,dp,wdf);
                    594:                gcdum(p,wf,wdf,wgcd);
                    595:                if ( DEG(wgcd) >= 1 )
                    596:                        continue;
                    597:                mini(p,dp,wf);
                    598:                if ( DEG(wf) <= 0 )
                    599:                        return;
                    600:        }
                    601: }
                    602:
                    603: int generate_primitive_root_enc(p,n,dp)
                    604: int p,n;
                    605: UM dp;
                    606: {
                    607:        int i,r,rj,j,q;
                    608:
1.5       noro      609:        if ( p == 2 && n == 1 )
                    610:                return 1;
                    611:
1.2       noro      612:        for ( i = 0, q = 1; i < n; i++ )
                    613:                 q *= p;
                    614:        for ( r = n==1?2:p; r < q; r++ ) {
1.1       noro      615:                rj = r;
1.2       noro      616:                for ( j = 1; j < q-1 && rj != 1; j++ )
                    617:                        rj = mulremum_enc(p,n,dp,rj,r);
                    618:                if ( j == q-1 )
1.1       noro      619:                        return r;
                    620:        }
1.2       noro      621: }
                    622:
                    623: /* [a(p)]*[b(p)] in GF(p^n) -> [a(x)*b(x) mod dp(x)]_{x->p} */
                    624:
                    625: int mulremum_enc(p,n,dp,a,b)
                    626: int p,n;
                    627: UM dp;
                    628: int a,b;
                    629: {
                    630:        int i,dr,r;
                    631:        UM wa,wb,wc,wq;
                    632:
                    633:        if ( n == 1 )
                    634:                return (a*b)%p;
                    635:        if ( !a || !b )
                    636:                return 0;
                    637:
                    638:        wa = W_UMALLOC(n);
                    639:        dec_um(p,a,wa);
                    640:
                    641:        wb = W_UMALLOC(n);
                    642:        dec_um(p,b,wb);
                    643:
                    644:        wc = W_UMALLOC(2*n);
                    645:        wq = W_UMALLOC(2*n);
                    646:        mulum(p,wa,wb,wc);
                    647:        dr = divum(p,wc,dp,wq);
                    648:        for ( i = dr, r = 0; i >= 0; i-- )
                    649:                r = r*p+COEF(wc)[i];
                    650:        return r;
1.5       noro      651: }
                    652:
                    653: void gfs_galois_action(a,e,c)
                    654: GFS a;
                    655: Q e;
                    656: GFS *c;
                    657: {
                    658:        Q p;
                    659:        int i,k;
                    660:        GFS t,s;
                    661:
                    662:        t = a;
                    663:        k = QTOS(e);
                    664:        STOQ(current_gfs_p,p);
                    665:        for ( i = 0; i < k; i++ ) {
                    666:                pwrgfs(t,p,&s); t = s;
                    667:        }
                    668:        *c = t;
                    669: }
                    670:
                    671: void qtogfs(a,c)
                    672: Q a;
                    673: GFS *c;
                    674: {
                    675:        int s;
                    676:
                    677:        s = QTOS(a)%current_gfs_q;
                    678:        if ( s < 0 )
                    679:                s += current_gfs_q;
                    680:        if ( !s )
                    681:                *c = 0;
                    682:        else
                    683:                MKGFS(current_gfs_ntoi[s],*c);
1.1       noro      684: }
                    685:
                    686: void mqtogfs(a,c)
                    687: MQ a;
                    688: GFS *c;
                    689: {
                    690:        if ( !a )
                    691:                *c = 0;
                    692:        else {
                    693:                MKGFS(current_gfs_ntoi[CONT(a)],*c);
                    694:        }
                    695: }
                    696:
                    697: void gfstomq(a,c)
                    698: GFS a;
                    699: MQ *c;
                    700: {
                    701:        if ( !a )
                    702:                *c = 0;
                    703:        else {
                    704:                UTOMQ(current_gfs_iton[CONT(a)],*c);
                    705:        }
                    706: }
                    707:
                    708: void ntogfs(a,b)
                    709: Obj a;
                    710: GFS *b;
                    711: {
                    712:        P t;
                    713:
                    714:        if ( !current_gfs_q1 )
                    715:                error("addgfs : current_gfs_q is not set");
                    716:        if ( !a || (OID(a)==O_N && NID(a) == N_GFS) )
                    717:                *b = (GFS)a;
                    718:        else if ( OID(a) == O_N && NID(a) == N_M )
                    719:                mqtogfs(a,b);
                    720:        else if ( OID(a) == O_N && NID(a) == N_Q ) {
1.4       noro      721:                ptomp(current_gfs_p,(P)a,&t); mqtogfs(t,b);
1.1       noro      722:        } else
                    723:                error("ntogfs : invalid argument");
                    724: }
                    725:
                    726: void addgfs(a,b,c)
                    727: GFS a,b;
                    728: GFS *c;
                    729: {
                    730:        int ai,bi,ci;
                    731:        GFS z;
                    732:
                    733:        ntogfs(a,&z); a = z;
                    734:        ntogfs(b,&z); b = z;
                    735:        if ( !a )
                    736:                *c = b;
                    737:        else if ( !b )
                    738:                *c = a;
                    739:        else {
                    740:                ai = CONT(a); bi = CONT(b);
                    741:                if ( ai > bi ) {
                    742:                        /* tab[ai]+tab[bi] = tab[bi](tab[ai-bi]+1) */
                    743:                        ci = current_gfs_plus1[ai-bi];
                    744:                        if ( ci < 0 )
                    745:                                *c = 0;
                    746:                        else {
                    747:                                ci += bi;
                    748:                                if ( ci >= current_gfs_q1 )
                    749:                                        ci -= current_gfs_q1;
                    750:                                MKGFS(ci,*c);
                    751:                        }
                    752:                } else {
                    753:                        /* tab[ai]+tab[bi] = tab[ai](tab[bi-ai]+1) */
                    754:                        ci = current_gfs_plus1[bi-ai];
                    755:                        if ( ci < 0 )
                    756:                                *c = 0;
                    757:                        else {
                    758:                                ci += ai;
                    759:                                if ( ci >= current_gfs_q1 )
                    760:                                        ci -= current_gfs_q1;
                    761:                                MKGFS(ci,*c);
                    762:                        }
                    763:                }
                    764:        }
                    765: }
                    766:
                    767: void subgfs(a,b,c)
                    768: GFS a,b;
                    769: GFS *c;
                    770: {
                    771:        GFS t,z;
                    772:
                    773:        ntogfs(a,&z); a = z;
                    774:        ntogfs(b,&z); b = z;
                    775:        if ( !b )
                    776:                *c = a;
                    777:        else {
                    778:                chsgngfs(b,&t);
                    779:                addgfs(a,t,c);
                    780:        }
                    781: }
                    782:
                    783: void mulgfs(a,b,c)
                    784: GFS a,b;
                    785: GFS *c;
                    786: {
                    787:        int ai;
                    788:        GFS z;
                    789:
                    790:        ntogfs(a,&z); a = z;
                    791:        ntogfs(b,&z); b = z;
                    792:        if ( !a || !b )
                    793:                *c = 0;
                    794:        else {
                    795:                ai = CONT(a) + CONT(b);
                    796:                if ( ai >= current_gfs_q1 )
                    797:                        ai -= current_gfs_q1;
                    798:                MKGFS(ai,*c);
                    799:        }
                    800: }
                    801:
                    802: void divgfs(a,b,c)
                    803: GFS a,b;
                    804: GFS *c;
                    805: {
                    806:        int ai;
                    807:        GFS z;
                    808:
                    809:        ntogfs(a,&z); a = z;
                    810:        ntogfs(b,&z); b = z;
                    811:        if ( !b )
                    812:                error("divgfs : division by 0");
                    813:        else if ( !a )
                    814:                *c = 0;
                    815:        else {
                    816:                ai = CONT(a) - CONT(b);
                    817:                if ( ai < 0 )
                    818:                        ai += current_gfs_q1;
                    819:                MKGFS(ai,*c);
                    820:        }
                    821: }
                    822:
                    823: void chsgngfs(a,c)
                    824: GFS a,*c;
                    825: {
                    826:        int ai;
                    827:        GFS z;
                    828:
                    829:        ntogfs(a,&z); a = z;
                    830:        if ( !a )
                    831:                *c = 0;
                    832:        else if ( current_gfs_q1&1 )
                    833:                *c = a;
                    834:        else {
                    835:                /* r^((q-1)/2) = -1 */
                    836:                ai = CONT(a)+(current_gfs_q1>>1);
                    837:                if ( ai >= current_gfs_q1 )
                    838:                        ai -= current_gfs_q1;
                    839:                MKGFS(ai,*c);
                    840:        }
                    841: }
                    842:
                    843: void pwrgfs(a,b,c)
                    844: GFS a;
                    845: Q b;
                    846: GFS *c;
                    847: {
                    848:        N an,tn,rn;
                    849:        GFS t,s,z;
                    850:
                    851:        ntogfs(a,&z); a = z;
                    852:        if ( !b )
                    853:                MKGFS(0,*c);
                    854:        else if ( !a )
                    855:                *c = 0;
                    856:        else {
                    857:                STON(CONT(a),an); muln(an,NM(b),&tn);
                    858:                STON(current_gfs_q1,an); remn(tn,an,&rn);
                    859:                if ( !rn )
                    860:                        MKGFS(0,*c);
                    861:                else if ( SGN(b) > 0 )
                    862:                        MKGFS(BD(rn)[0],*c);
                    863:                else {
                    864:                        MKGFS(0,t);
                    865:                        MKGFS(BD(rn)[0],s);
                    866:                        divgfs(t,s,c);
                    867:                }
                    868:        }
                    869: }
                    870:
                    871: int cmpgfs(a,b)
                    872: GFS a,b;
                    873: {
                    874:        GFS z;
                    875:
                    876:        ntogfs(a,&z); a = z;
                    877:        if ( !a )
                    878:                return !b ? 0 : -1;
                    879:        else
                    880:                if ( !b )
                    881:                        return 1;
                    882:                else {
                    883:                        if ( CONT(a) > CONT(b) )
                    884:                                return 1;
                    885:                        else if ( CONT(a) < CONT(b) )
                    886:                                return -1;
                    887:                        else
                    888:                                return 0;
                    889:                }
1.3       noro      890: }
                    891:
                    892: void randomgfs(r)
                    893: GFS *r;
                    894: {
                    895:        unsigned int t;
                    896:
                    897:        if ( !current_gfs_q1 )
                    898:                error("addgfs : current_gfs_q is not set");
                    899:        t = mt_genrand()%current_gfs_q;
                    900:        if ( !t )
                    901:                *r = 0;
                    902:        else {
                    903:                if ( t == current_gfs_q1 )
                    904:                        t = 0;
                    905:                MKGFS(t,*r);
                    906:        }
1.1       noro      907: }
1.6     ! noro      908:
        !           909: /* arithmetic operations for 'immediate values of GFS */
        !           910:
        !           911: int _addsf(a,b)
        !           912: int a,b;
        !           913: {
        !           914:        if ( !a )
        !           915:                return b;
        !           916:        else if ( !b )
        !           917:                return a;
        !           918:
        !           919:        a = IFTOF(a); b = IFTOF(b);
        !           920:        if ( a > b ) {
        !           921:                /* tab[a]+tab[b] = tab[b](tab[a-b]+1) */
        !           922:                a = current_gfs_plus1[a-b];
        !           923:                if ( a < 0 )
        !           924:                        return 0;
        !           925:                else {
        !           926:                        a += b;
        !           927:                        if ( a >= current_gfs_q1 )
        !           928:                                a -= current_gfs_q1;
        !           929:                        return FTOIF(a);
        !           930:                }
        !           931:        } else {
        !           932:                /* tab[a]+tab[b] = tab[a](tab[b-a]+1) */
        !           933:                b = current_gfs_plus1[b-a];
        !           934:                if ( b < 0 )
        !           935:                        return 0;
        !           936:                else {
        !           937:                        b += a;
        !           938:                        if ( b >= current_gfs_q1 )
        !           939:                                b -= current_gfs_q1;
        !           940:                        return FTOIF(b);
        !           941:                }
        !           942:        }
        !           943: }
        !           944:
        !           945: int _chsgnsf(a)
        !           946: int a;
        !           947: {
        !           948:        if ( !a )
        !           949:                return 0;
        !           950:        else if ( current_gfs_q1&1 )
        !           951:                return a;
        !           952:        else {
        !           953:                /* r^((q-1)/2) = -1 */
        !           954:                a = IFTOF(a);
        !           955:                a += (current_gfs_q1>>1);
        !           956:                if ( a >= current_gfs_q1 )
        !           957:                        a -= current_gfs_q1;
        !           958:                return FTOIF(a);
        !           959:        }
        !           960: }
        !           961:
        !           962: int _subsf(a,b)
        !           963: int a,b;
        !           964: {
        !           965:        if ( !a )
        !           966:                return _chsgnsf(b);
        !           967:        else if ( !b )
        !           968:                return a;
        !           969:        else
        !           970:                return _addsf(a,_chsgnsf(b));
        !           971: }
        !           972:
        !           973: int _mulsf(a,b)
        !           974: int a,b;
        !           975: {
        !           976:        if ( !a || !b )
        !           977:                return 0;
        !           978:        else {
        !           979:                a = IFTOF(a) + IFTOF(b);
        !           980:                if ( a >= current_gfs_q1 )
        !           981:                        a -= current_gfs_q1;
        !           982:                return FTOIF(a);
        !           983:        }
        !           984: }
        !           985:
        !           986: int _invsf(a)
        !           987: int a;
        !           988: {
        !           989:        if ( !a )
        !           990:                error("_invsf : division by 0");
        !           991:        else {
        !           992:                a = current_gfs_q1 - IFTOF(a);
        !           993:                return FTOIF(a);
        !           994:        }
        !           995: }
        !           996:
        !           997: int _divsf(a,b)
        !           998: int a,b;
        !           999: {
        !          1000:        if ( !b )
        !          1001:                error("_divsf : division by 0");
        !          1002:        else if ( !a )
        !          1003:                return 0;
        !          1004:        else {
        !          1005:                a = IFTOF(a) - IFTOF(b);
        !          1006:                if ( a < 0 )
        !          1007:                        a += current_gfs_q1;
        !          1008:                return FTOIF(a);
        !          1009:        }
        !          1010: }
        !          1011:
        !          1012: int _pwrsf(a,b)
        !          1013: int a,b;
        !          1014: {
        !          1015:        GFS at,ct;
        !          1016:        Q bt;
        !          1017:        int c;
        !          1018:
        !          1019:        if ( !b )
        !          1020:                return _onesf();
        !          1021:        else if ( !a )
        !          1022:                return 0;
        !          1023:        else {
        !          1024:                a = IFTOF(a);
        !          1025:                MKGFS(a,at);
        !          1026:                STOQ(b,bt);
        !          1027:                pwrgfs(at,bt,&ct);
        !          1028:                c = CONT(ct);
        !          1029:                return FTOIF(c);
        !          1030:        }
        !          1031: }
        !          1032:
        !          1033: int _onesf()
        !          1034: {
        !          1035:        return FTOIF(0);
        !          1036: }
        !          1037:
        !          1038: int _itosf(n)
        !          1039: int n;
        !          1040: {
        !          1041:        int i;
        !          1042:
        !          1043:        n %= current_gfs_p;
        !          1044:        if ( !n )
        !          1045:                return 0;
        !          1046:        i = current_gfs_ntoi[n];
        !          1047:        i = FTOIF(i);
        !          1048:        if ( n < 0 )
        !          1049:                i = _chsgnsf(i);
        !          1050:        return i;
        !          1051: }
        !          1052:
        !          1053: int _isonesf(a)
        !          1054: int a;
        !          1055: {
        !          1056:        return a == FTOIF(0);
        !          1057: }
        !          1058:
        !          1059: int _randomsf()
        !          1060: {
        !          1061:        int t;
        !          1062:
        !          1063:        t = (int) (mt_genrand() % current_gfs_q1);
        !          1064:        if ( !t )
        !          1065:                return 0;
        !          1066:        else
        !          1067:                return FTOIF(t);
        !          1068: }
        !          1069:
        !          1070: int field_order_sf()
        !          1071: {
        !          1072:        return current_gfs_q;
        !          1073: }
        !          1074:
        !          1075: int characteristic_sf()
        !          1076: {
        !          1077:        return current_gfs_p;
        !          1078: }
        !          1079:

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>