fork download
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. typedef long long LL;
  6.  
  7. LL n, q;
  8.  
  9. int main()
  10. {
  11. cin >> n >> q;
  12. LL x[n];
  13. for (int i = 0; i < n; ++i)
  14. cin >> x[i];
  15.  
  16. LL cnt = 1, num = 1;
  17. while (cnt <= q) {
  18. for (int i = 0; i < n; ++i) {
  19. if (num % x[i] == 0 && cnt <= q) {
  20. ++cnt;
  21. cout << i+1 << " ";
  22. }
  23. }
  24. ++num;
  25. }
  26.  
  27.  
  28. return 0;
  29. }
  30.  
Success #stdin #stdout 0s 3464KB
stdin
2 5
1 3
stdout
1 1 1 2 1