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