fork download
  1.  
  2. #include <cstring>
  3. #include <cstdio>
  4.  
  5. using namespace std;
  6.  
  7. bool check[1000001], exist[1000001];
  8. long long ans[1000000];
  9. int start[1000001];
  10.  
  11. int main() {
  12. int m, limit = 0;
  13. scanf("%d", &m);
  14. memset(check, false, sizeof(check));
  15. for (int i = 0; i < m; i ++) {
  16. int x;
  17. scanf("%d", &x);
  18. check[x] = true;
  19. if (x > limit) limit = x;
  20. }
  21.  
  22. int n, tot = 0;
  23. scanf("%d", &n);
  24. long long now = 0;
  25. memset(exist, false, sizeof(exist));
  26. for (int i = 1; i <= limit; i ++) start[i] = i;
  27. for (int i = 0; i < n; i ++) {
  28. int x;
  29. scanf("%d", &x);
  30. int cur = start[x];
  31. for (int j = 0; j < x; j ++) {
  32. while (exist[cur]) {
  33. cur += x;
  34. if (cur > limit) break;
  35. }
  36. start[x] = cur;
  37. if (cur > limit) break;
  38. exist[cur] = true;
  39. if (check[cur]) ans[tot ++] = now + j;
  40. }
  41. now += x;
  42. }
  43.  
  44. printf("%d\n", tot);
  45. for (int i = 0; i < tot; i ++) printf("%lld\n", ans[i] + 1);
  46.  
  47. return 0;
  48. }
  49.  
Success #stdin #stdout 0.01s 16400KB
stdin
4
1
6
8
16
3
4
2
4
stdout
3
2
4
6