fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define int long long int
  4. #define double long double
  5. inline int power(int a, int b) {
  6. int x = 1;
  7. while (b) {
  8. if (b & 1) x *= a;
  9. a *= a;
  10. b >>= 1;
  11. }
  12. return x;
  13. }
  14.  
  15.  
  16. const int M = 1000000007;
  17. const int N = 3e5+9;
  18. const int INF = 2e9+1;
  19. const int LINF = 2000000000000000001;
  20.  
  21. //_ ***************************** START Below *******************************
  22.  
  23.  
  24. string consistency(int n, int k) {
  25. string s(n, '9');
  26. if(k==1 || k==9 || k==3){
  27. return s;
  28. }
  29. if(k==2){
  30. if(n==1) return "8";
  31. s[0] = '8';
  32. s[n-1] = '8';
  33. return s;
  34. }
  35. if(k==4){
  36. if(n==1) return "8";
  37. if(n==2) return "88";
  38. if(n==3) return "888";
  39. s[0] = '8';
  40. s[1] = '8';
  41. s[n-2] = '8';
  42. s[n-1] = '8';
  43. return s;
  44. }
  45. if(k==5){
  46. if(n==1) return "5";
  47. s[0] = '5';
  48. s[n-1] = '5';
  49. return s;
  50. }
  51. if(k==6){
  52. if(n==1) return "6";
  53. if(n==2) return "66";
  54.  
  55. s[0] = '8';
  56. s[n-1] = '8';
  57.  
  58. if(n&1){
  59. s[n/2] = '8';
  60. }
  61. else{
  62. s[n/2] = '7';
  63. s[n/2-1] = '7';
  64. }
  65. return s;
  66. }
  67. if(k==8){
  68. if(n==1) return "8";
  69. if(n==2) return "88";
  70. if(n==3) return "888";
  71. if(n==4) return "8888";
  72. if(n==5) return "88888";
  73.  
  74. s[0] = '8';
  75. s[1] = '8';
  76. s[2] = '8';
  77. s[n-3] = '8';
  78. s[n-2] = '8';
  79. s[n-1] = '8';
  80. return s;
  81. }
  82.  
  83. //* Solve for k=7 later
  84. return "";
  85.  
  86. }
  87.  
  88.  
  89. void solve() {
  90.  
  91. int n, k;
  92. cin >> n >> k;
  93.  
  94. cout << consistency(n, k) << endl ;
  95.  
  96. }
  97.  
  98.  
  99.  
  100.  
  101.  
  102. int32_t main() {
  103. ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  104.  
  105. int t = 1;
  106. cin >> t;
  107. while (t--) {
  108. solve();
  109. }
  110.  
  111. return 0;
  112. }
Success #stdin #stdout 0.01s 5320KB
stdin
5
4 7
6 7
7 7
8 8
20 7
stdout


88899888