fork(10) download
  1. /*
  2. written by- Piyush Golani
  3. language- c++
  4. country- India
  5. College- N.I.T Jamshedpur
  6. */
  7. #include <cmath>
  8. #include <ctime>
  9. #include <iostream>
  10. #include <string>
  11. #include <vector>
  12. #include<cstdio>
  13. #include<sstream>
  14. #include<algorithm>
  15. #include<cstdlib>
  16. #include<cstring>
  17. #include<map>
  18. #include<cctype>
  19. #include<queue>
  20. using namespace std;
  21. #define pb push_back
  22. #define all(s) s.begin(),s.end()
  23. #define f(i,a,b) for(int i=a;i<b;i++)
  24. #define F(i,a,b) for(int i=a;i>=b;i--)
  25. #define PI 3.1415926535897932384626433832795
  26. #define INF 1000000005
  27. #define BIG_INF 7000000000000000000LL
  28. #define mp make_pair
  29. #define eps 1e-9
  30. #define LL long long
  31. #define si(n) scanf("%d",&n)
  32. #define sll(n) scanf("%lld",&n)
  33. #define mod 1000000007
  34.  
  35.  
  36.  
  37. bool visited[20005];
  38.  
  39.  
  40. int main()
  41. {
  42. int t;
  43. si(t);
  44. while(t--)
  45. {
  46. LL n;
  47. sll(n);
  48. memset(visited,false,sizeof(visited));
  49. queue<LL> Q;
  50. Q.push(1);
  51. while(!Q.empty())
  52. {
  53. LL p= Q.front();
  54. Q.pop();
  55. if(visited[p%n]==1) continue;
  56. visited[p%n]=1;
  57. if(p%n==0)
  58. {
  59. printf("%lld\n",p);
  60. break;
  61. }
  62. Q.push(p*10);
  63. Q.push(p*10+1);
  64. }
  65. }
  66. return 0;
  67. }
  68.  
Runtime error #stdin #stdout 0.02s 2876KB
stdin
Standard input is empty
stdout
Standard output is empty