fork download
  1. const fi='';
  2. fo='';
  3. maxn=201;
  4. type point=record
  5. x,y:integer;
  6. end;
  7. var q:array[1..maxn*maxn+1] of point;
  8. f:array[0..maxn,0..maxn] of longint;
  9. t,n:integer;
  10. d,c:longint;
  11. procedure xuat(x,y:integer);
  12. var i:integer;
  13. begin
  14. for i:=1 to x do write('8');
  15. for i:=1 to y do write('6');
  16. writeln;
  17. end;
  18. procedure push(x,y:integer);
  19. begin
  20. inc(c);
  21. q[c].x:= x;
  22. q[c].y := y;
  23. end;
  24. function mu(a:integer):longint;
  25. var i:integer;
  26. tam:longint;
  27. begin
  28. tam:=1;
  29. for i:=1 to a do tam:=(tam*10) mod n;
  30. exit(tam);
  31. end;
  32. procedure xuly;
  33. var
  34. x,y:integer;
  35. begin
  36.  
  37. d:=1;c:=1;
  38. q[1].x:=0;q[1].y:=0;
  39.  
  40. while d<=c do
  41. begin
  42. x:=q[d].x; y:=q[d].y;
  43. inc(d);
  44. if (x+y>0) and (f[x,y]=0) then begin xuat(x,y); exit; end;
  45.  
  46. if (y+1+x<=200) and (f[x,y+1]=-1) then
  47. begin
  48. f[x,y+1]:= (f[x,y]*10 +6) mod n ;
  49. push(x,y+1);
  50. end;
  51.  
  52. if (x+1+y<=200) and (f[x+1,y]=-1) then
  53. begin
  54. f[x+1,y]:=(8*mu(x+y) mod n + f[x,y] ) mod n ;
  55. push(x+1,y);
  56. end;
  57.  
  58. if x+y>200 then begin writeln(-1); exit; end;
  59. end;
  60. writeln(-1);
  61. end;
  62. procedure init;
  63. var i,j:integer;
  64. begin
  65. for i:=0 to 200 do
  66. for j:=0 to 200 do f[i,j]:=-1;
  67.  
  68. f[0,0]:=0;
  69. end;
  70. procedure main;
  71. var i:integer;
  72. begin
  73. assign(input,fi);reset(input);
  74. assign(output,fo);rewrite(output);
  75.  
  76. readln(t);
  77. for i:=1 to t do
  78. begin
  79.  
  80. readln(n);
  81. init;
  82. xuly;
  83.  
  84. end;
  85.  
  86. close(input);close(output);
  87. end;
  88. begin
  89. main;
  90. end.
  91.  
Success #stdin #stdout 0s 656KB
stdin
Standard input is empty
stdout
Standard output is empty