标签:
坑啊= =
选了好几次质数,发现还是这一组靠谱
思路:每次mod之后求出所有解,再mod再求,看着复杂度差不多了就把没重复的都输出就行了
const mi:array[1..7] of int64=(12537,15437,17647,14677,10003,10009,10007); var n,m,shi,sum,x:int64; i,j,k,y1:longint; a:array[-1..102,-1..10000+9] of int64; flag:array[-1..1000000+9] of boolean; c:char; b:array[-1..102,1..7] of int64; f:array[-1..100000,1..7] of boolean; begin readln(n,m); fillchar(flag,sizeof(flag),true); fillchar(f,sizeof(f),true); for i:=0 to n do begin read(c); if c=‘-‘ then begin j:=0; y1:=-1; end else begin y1:=1; j:=1; val(c,a[i,1],k); end; a[i,1]:=a[i,1]*y1; while not eoln do begin inc(j); read(c); val(c,a[i,j],k); a[i,j]:=a[i,j]*y1; end; a[i,0]:=j; readln; end; for k:=1 to 7 do for i:=0 to n do begin shi:=1; for j:=a[i,0] downto 1 do begin b[i,k]:=(b[i,k]+a[i,j]*shi mod mi[k]) mod mi[k]; shi:=shi*10 mod mi[k]; end; end; for k:=1 to 7 do for i:=1 to mi[k] do begin sum:=0; x:=1; for j:=0 to n do begin sum:=(sum+x*b[j,k] mod mi[k]) mod mi[k]; x:=x*i mod mi[k]; end; if sum<>0 then f[i,k]:=false; end; sum:=0; for i:=1 to m do for k:=1 to 7 do if not f[i mod mi[k],k] then begin flag[i]:=false; break; end; for i:=1 to m do if flag[i] then inc(sum); writeln(sum); for i:=1 to m do if flag[i] then writeln(i); end.
想学会这道题的同学们一定要自己打一遍,很重要23333
喜欢就收藏一下,vic私人qq:1064864324,加我一起讨论问题,一起进步^-^
标签:
原文地址:http://www.cnblogs.com/victorslave/p/4827107.html