存代码:
1 #include<cstdio> 2 #include<cstdlib> 3 #include<cstring> 4 #include<iostream> 5 #include<algorithm> 6 #include<queue> 7 #include<cmath> 8 using namespace std; 9 #define M1 100007 10 #define M2 22901 11 #define M3 22907 12 #define Maxm 1000010 13 #define Maxn 110 14 #define Maxd 10010 15 #define LL long long 16 17 int n,m; 18 19 LL a[5][Maxn]; 20 char s[Maxd]; 21 22 int op[Maxm]; 23 24 int mymin(int x,int y) {return x<y?x:y;} 25 26 bool check(LL x) 27 { 28 LL a1=0,a2=0,a3=0; 29 for(int i=n;i>=0;i--) 30 { 31 a1=(a1*x+a[0][i])%M1; 32 a2=(a2*x+a[1][i])%M2; 33 a3=(a3*x+a[2][i])%M3; 34 } 35 return a1==0&&a2==0&&a3==0; 36 } 37 38 bool ok[100010]; 39 40 int main() 41 { 42 int l; 43 scanf("%lld%lld",&n,&m); 44 for(int i=0;i<=n;i++) 45 { 46 scanf("%s",s); 47 l=strlen(s); 48 a[0][i]=a[1][i]=0; 49 int f=1; 50 for(int j=0;j<l;j++) 51 { 52 if(s[j]=='-') {f=-1;continue;} 53 a[0][i]=(a[0][i]*10+s[j]-'0')%M1; 54 a[1][i]=(a[1][i]*10+s[j]-'0')%M2; 55 a[2][i]=(a[2][i]*10+s[j]-'0')%M3; 56 } 57 a[0][i]*=f;a[1][i]*=f;a[2][i]*=f; 58 } 59 op[0]=0; 60 int cnt=0; 61 memset(ok,0,sizeof(ok)); 62 for(int i=1;i<=m;i++) 63 { 64 if(check((LL)i)) op[++op[0]]=i;//,ok[i]=1; 65 // if(op[0]>n) break; 66 } 67 /*for(int i=mymin(100000,m)+1;i<=m;i++) 68 { 69 if(ok[i%M1]&&ok[i%M2]&&ok[i%M3]) op[++op[0]]=i; 70 }*/ 71 printf("%d ",op[0]); 72 for(LL i=1;i<=op[0];i++) printf("%d ",op[i]); 73 return 0; 74 }