fork(4) download
  1. var l,ans,n,m,q,ost,q1:int64;
  2. i,j,t,p,x:longint;
  3. s:string;
  4. ok:boolean;
  5. a,qq:array [0..300000,0..101] of int64;
  6. aa,kol:array [0..200] of longint;
  7. begin
  8. read(q1,m);
  9. str(q1,s);
  10. l:=length(s);
  11. for i:=1 to l do
  12. begin
  13. val(s[i],aa[i],p);
  14. inc(kol[aa[i]]);
  15. end;
  16. for i:=1 to l do
  17. if aa[i]>0 then a[1 shl (i-1),aa[i] mod m]:=1;
  18. q:=(1 shl (l))-1;
  19. for i:=1 to q do
  20. begin
  21. for j:=1 to l do
  22. begin
  23. if ((1 shl (j-1)) and i=0) then begin
  24. ok:=true;
  25. for x:=1 to j-1 do
  26. if (aa[j]=aa[x]) and ((1 shl (x-1)) and i=0) then begin ok:=false; break; end;
  27. for x:=j+1 to l do
  28. if (aa[j]=aa[x]) and ((1 shl (x-1)) and i>0) then begin ok:=false; break; end;
  29. if not(ok) then continue;
  30.  
  31. inc(qq[i,0]);
  32. qq[i,qq[i,0]]:=j;
  33. end;
  34. end;
  35. end;
  36.  
  37. for i:=1 to q do
  38. begin
  39. for j:=0 to m-1 do
  40. begin
  41. if a[i,j]=0 then continue;
  42. for t:=1 to qq[i,0] do
  43. begin
  44. ost:=(j*10+aa[qq[i][t]]) mod m;
  45. inc(a[i+(1 shl (qq[i][t]-1)),ost],a[i][j]);
  46. end;
  47. end;
  48. end;
  49. writeln(a[q][0]);
  50. end.
Runtime error #stdin #stdout 0s 478336KB
stdin
Standard input is empty
stdout
Runtime error 106 at $080480D8
  $080480D8
  $08063C53