| 1 | #include <stdio.h> |
|---|
| 2 | #include <stdlib.h> |
|---|
| 3 | #include <math.h> |
|---|
| 4 | #include "ellcurv.h" |
|---|
| 5 | |
|---|
| 6 | char INPUT[1024]; char *a; int64 BOUND=9765625; int NB,nb; |
|---|
| 7 | |
|---|
| 8 | int my_getline() {a=fgets(INPUT,128,stdin); if (NULL==a) return(0); return(1);} |
|---|
| 9 | |
|---|
| 10 | void topcheck() |
|---|
| 11 | {char *GO; char GO2[128]; int64 N; int OK=1; int i,cnt; |
|---|
| 12 | double f; int l=0; int r=0; |
|---|
| 13 | GO=malloc(128); |
|---|
| 14 | sscanf(INPUT,"%s",GO); N=atoll(GO); if ((N<11) || (N>BOUND)) OK=0; |
|---|
| 15 | sscanf(INPUT,"%s %s",GO,GO); if ((GO[0]!='[')||(GO[strlen(GO)-1]!=']')) OK=0; |
|---|
| 16 | for (i=0;i<strlen(GO);i++) {if (GO[i]=='[') l++; if (GO[i]==']') r++;} |
|---|
| 17 | if ((l!=1) || (r!=1)) OK=0; |
|---|
| 18 | sscanf(INPUT,"%s %s %s",GO,GO,GO); i=atoi(GO); if ((i<0) || (i>6)) OK=0; |
|---|
| 19 | sscanf(INPUT,"%s %s %s %s",GO,GO,GO,GO); f=atof(GO); |
|---|
| 20 | if ((f<0.0) || (f>100000.0)) OK=0; |
|---|
| 21 | sscanf(INPUT,"%s %s %s %s %s",GO,GO,GO,GO,GO); i=atoi(GO); |
|---|
| 22 | if ((i<1) || (i>163)) OK=0; |
|---|
| 23 | sscanf(INPUT,"%s %s %s %s %s %s",GO,GO,GO,GO,GO,GO); |
|---|
| 24 | if ((!strcmp(GO,"X")) && (!strcmp(GO,"+X")) && (!strcmp(GO,"+*X"))) |
|---|
| 25 | {if (GO[0]=='+') GO++; if (GO[0]=='*') GO++; N=atoll(GO); if (N<1) OK=0;} |
|---|
| 26 | cnt=0; for (i=0;i<strlen(INPUT);i++) if (INPUT[i]==' ') cnt++; |
|---|
| 27 | if (cnt!=5) OK=0; if (!OK) {printf("FAILTOP\n%s\n",INPUT); exit(-2);} |
|---|
| 28 | free(GO); |
|---|
| 29 | } |
|---|
| 30 | |
|---|
| 31 | int ISOK(int i) |
|---|
| 32 | {int j; if (i<1) return(0); |
|---|
| 33 | if (i==1) return(1); if (i==4) return(1); if (i==9) return(1); |
|---|
| 34 | if (i==16) return(1); j=(int) sqrt(i); if (i!=j*j) return(0); return(1); |
|---|
| 35 | } |
|---|
| 36 | |
|---|
| 37 | void bigcheck(int CC) |
|---|
| 38 | {char GO[128]; char GO2[128]; int l=0; int r=0; int i=0; int OK=1; int cnt; |
|---|
| 39 | GEN Q,PV; int b,j,t; |
|---|
| 40 | |
|---|
| 41 | sscanf(INPUT,"%s",GO); if ((GO[0]!='[') || (GO[strlen(GO)-1]!=']')) OK=0; |
|---|
| 42 | for (i=0;i<strlen(GO);i++) {if (GO[i]=='[') l++; if (GO[i]==']') r++;} |
|---|
| 43 | if ((l!=1) || (r!=1)) {printf("FAILBIG1\n%s\n",INPUT); exit(-2);} |
|---|
| 44 | sscanf(INPUT,"%s %s",GO,GO); l=0; r=0; |
|---|
| 45 | if (GO[0]=='[') |
|---|
| 46 | {for (i=0;i<strlen(GO);i++) {if (GO[i]=='[') l++; if (GO[i]==']') r++;} |
|---|
| 47 | if ((l!=1) || (r!=1)) OK=0; if (GO[strlen(GO)-1]!=']') OK=0; |
|---|
| 48 | } |
|---|
| 49 | else if (GO[0]=='(') |
|---|
| 50 | {for (i=0;i<strlen(GO);i++) {if (GO[i]=='(') l++; if (GO[i]==')') r++;} |
|---|
| 51 | if ((l!=1) || (r!=1)) OK=0; if (GO[strlen(GO)-1]!=')') OK=0; |
|---|
| 52 | } |
|---|
| 53 | else OK=0; |
|---|
| 54 | sscanf(INPUT,"%s %s %s",GO,GO,GO); |
|---|
| 55 | if (strcmp(GO,"X")) if (!ISOK(atoi(GO))) OK=0; |
|---|
| 56 | sscanf(INPUT,"%s %s %s %s",GO,GO,GO,GO); |
|---|
| 57 | if (GO[strlen(GO)-1]=='x') GO[strlen(GO)-1]=0; |
|---|
| 58 | i=atoi(GO); if ((i<1) || (i>12)) OK=0; |
|---|
| 59 | cnt=0; for (i=0;i<strlen(INPUT);i++) {if (INPUT[i]==' ') cnt++; nb++;} |
|---|
| 60 | if (cnt!=3) OK=0; if (!OK) {printf("FAILBIG2\n%s\n",INPUT); exit(-2);} |
|---|
| 61 | if (nb>CC) |
|---|
| 62 | {sscanf(INPUT,"%s",GO); CURVE=getcurve(GO); |
|---|
| 63 | Q=cgetg(20,t_VEC); for (j=1;j<=13;j++) Q[j]=CURVE[j]; |
|---|
| 64 | b=4+((lgefint((GEN) Q[12])-2)>>1); PV=periodvolvec0(Q,b+2); |
|---|
| 65 | Q[15]=PV[2]; Q[16]=PV[3]; Q[14]=(long) gzero; Q[17]=(long) gzero; |
|---|
| 66 | Q[18]=(long) gzero; Q[19]=(long) gzero; |
|---|
| 67 | t=itos((GEN) elltors0(Q,0)[1]); sscanf(INPUT,"%s %s %s %s",GO,GO,GO,GO); |
|---|
| 68 | if (GO[strlen(GO)-1]=='x') {GO[strlen(GO)-1]=0; i=2*atoi(GO);} |
|---|
| 69 | else i=atoi(GO); if (t!=i) {printf("FAILTORS\n%s\n",INPUT);} |
|---|
| 70 | } |
|---|
| 71 | } |
|---|
| 72 | |
|---|
| 73 | void processhead(int CC) |
|---|
| 74 | {int64 N; char GO[128]; int I,J,b,i; |
|---|
| 75 | pari_sp memspot; |
|---|
| 76 | sscanf(INPUT,"%s",GO); topcheck(); N=atoll(GO); nb+=strlen(INPUT); |
|---|
| 77 | if (GO[0]=='[') {printf("FAILPROC\n%s\n",INPUT); exit(-2);} |
|---|
| 78 | sscanf(INPUT,"%s %s %s %s %s",GO,GO,GO,GO,GO); |
|---|
| 79 | ISOG=atoi(GO); I=classsize(); J=ISOG; |
|---|
| 80 | memspot=avma; |
|---|
| 81 | for (i=0;i<I;i++) |
|---|
| 82 | {b=my_getline(); bigcheck(CC); |
|---|
| 83 | if ((!i) && (nb>CC) && 0) |
|---|
| 84 | {sscanf(INPUT,"%s",GO); CURVE=getcurve(GO); |
|---|
| 85 | ROOTNO=-1; TAMA=gun; COND=gun; ISOG=0; PLACE=0; CURVES=gzero; |
|---|
| 86 | ISPRIME=0; ISSQFREE=0; ISSETZER=0; MODDEG=gzero; CM=0; AISOG=0; NI=0; |
|---|
| 87 | CURVE=minimalequation(); minimaltwist(); symsq(); isogenies(); |
|---|
| 88 | AISOG=absval(ISOG); |
|---|
| 89 | if (J!=AISOG) {printf("FAILISOG\n%s\n",INPUT); exit(-2);} |
|---|
| 90 | } |
|---|
| 91 | } |
|---|
| 92 | avma=memspot; //if (nb>NB) {printf("%i\n",nb); NB+=1000000;} |
|---|
| 93 | } |
|---|
| 94 | |
|---|
| 95 | void checkit(int CC) |
|---|
| 96 | {int b; |
|---|
| 97 | if (CC==-1) CC++; CC*=1000000; |
|---|
| 98 | BOUND<<=10; a=malloc(128); VERBOSE=0; NB=CC+1000000; |
|---|
| 99 | while(1) {b=my_getline(); if (!b) break; processhead(CC);} |
|---|
| 100 | } |
|---|