fork(8) download
  1. # include <iostream>
  2. # include <iomanip>
  3. # include <cstdio>
  4. # include <cstring>
  5. # include <queue>
  6. using namespace std;
  7.  
  8. unsigned long long Input;
  9. const int BASE = 100000;
  10. bool exist[20000];
  11.  
  12. class BigInteger
  13. {
  14. public:
  15. int num[10];
  16. int len;
  17. BigInteger& mul10()
  18. {
  19. int c = 0;
  20. for(int i=0;i<len;i++)
  21. {
  22. num[i] = num[i]*10 + c;
  23. c = num[i]/BASE;
  24. num[i]%=BASE;
  25. }
  26. if(c)
  27. {
  28. num[len++] = c;
  29. }
  30. return *this;
  31. }
  32. BigInteger& add(int c)
  33. {
  34. for(int i=0;c&&i<len;i++)
  35. {
  36. num[i] = num[i] + c;
  37. c = num[i]/BASE;
  38. num[i]%=BASE;
  39. }
  40. if(c)
  41. {
  42. num[len++] = c;
  43. }
  44. return *this;
  45. }
  46. int operator%(const int& a)
  47. {
  48. int c = 0;
  49. for(int i=len-1;i>=0;i--)
  50. {
  51. c*=BASE;
  52. c+=num[i];
  53. c%=a;
  54. }
  55. return c;
  56. }
  57. };
  58.  
  59. ostream& operator<<(ostream& out, const BigInteger& a)
  60. {
  61. out << a.num[a.len-1];
  62. for(int i=a.len-2;i>=0;i--)
  63. {
  64. out << right << setfill('0') << setw(5) << a.num[i];
  65. }
  66. return out;
  67. }
  68.  
  69. int main(int argc, char const *argv[])
  70. {
  71. int N;
  72. cin >> N;
  73. BigInteger current;
  74. queue <BigInteger> Queue;
  75. BigInteger ten;
  76. ten.len = 1;
  77. ten.num[0] = 10;
  78. BigInteger eleven;
  79. eleven.len = 1;
  80. eleven.num[0] = 11;
  81. int maxlen = -1,j=-1;
  82. for (int i = 1; i <= N; i++)
  83. {
  84. cin >> Input;
  85. memset(exist,0,sizeof(exist));
  86. if (Input == 1) {cout << "1" << endl; continue;}
  87. Queue.push (ten); Queue.push (eleven);
  88. while (!Queue.empty())
  89. {
  90. current = Queue.front();
  91. Queue.pop();
  92. int temp = current % Input;
  93. if(exist[temp]) continue;
  94. exist[temp] = 1;
  95. if (temp)
  96. {
  97. Queue.push (current.mul10());
  98. Queue.push (current.add(1));
  99. }
  100. else
  101. {
  102. cout << current << endl;
  103. while (!Queue.empty()) Queue.pop();
  104. }
  105. }
  106. }
  107. return 0;
  108. }
Success #stdin #stdout 0.02s 2880KB
stdin
4
17
11011
17
19998
stdout
11101
11011
11101
1111111111111111111111111111111111110