int main() { LL tot = 1; while(scanf("%lld %lld %lld %lld",&C,&k1,&b1,&k2)!=EOF) { printf("Case #%d:\n",tot++); LL s = 0; for(LL i = 1; i<C; i++) ///枚举a { bool ok = true; LL b = C - poww(i,k1+b1); ///求b if(b<=0) continue; for(LL n =3000 ; n<=3500; n++) ///筛选 { LL rr = n; if(((LL)poww(i,k1*rr+b1)+(LL)poww(b,k2*rr-k2+1))%C!=0) { ok = false; break; } } if(ok) { printf("%lld %lld\n",i,b); s++; } } if(!s) ///无解! { puts("-1"); } } return 0; }
int binary_decimal(int n){ int decimal=0, i=0, r; while (n!=0) { r = n%10; n/=10; decimal += r*poww(2,i); ++i; } return decimal; }
void decoder(int *table, char *buffer){ int count = 0; int i = 8; while(isdigit(buffer[i])){ count++; i++; } char inparr[count]; i = 8; int i1 = 0; while(i1<count){ inparr[i1] = buffer[i]; i1++; i++; } int inpnum = atoi(inparr); int outnum = poww(2,inpnum); char inputvars[inpnum]; char outputvars[outnum]; int o = i + 1; i = 0; while(i<inpnum){ inputvars[i] = buffer[o]; i++; o = o+2; } i=0; while(i<outnum){ outputvars[i] = buffer[o]; table[(int)outputvars[i]] = 0; /*set default for outputs to 0 */ i++; o = o+2; } i = 0; int select[inpnum]; while(i<inpnum){ select[i] = table[(int)inputvars[i]]; i++; } int selected = 0; for (i = 0; i < inpnum; i++){ selected = 10 * selected + select[i]; } int gray = getbin(selected); int dex = binary_decimal(gray); table[(int)outputvars[dex]] = 1; }
int getgray(int bin){ int a, b; int result = 0; int i = 0; while (bin != 0){ a = bin % 10; bin = bin / 10; b = bin % 10; if ((a && !b) || (!a && b)){ result = result + poww(10, i); } i++; } return result; }