Datasets:

Modalities:
Image
Text
Formats:
parquet
Size:
< 1K
Tags:
code
Libraries:
Datasets
pandas
License:
File size: 885 Bytes
ff444f7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#include <iostream>
#include <vector>
using namespace std;

int solve() {
  int N, Q;
  cin >> N;
  vector<bool> white(N + 1);
  for (int i = 1; i <= N; i++) {
    char c;
    cin >> c;
    white[i] = c - '0';
  }
  vector<bool> press(N + 1);
  cin >> Q;
  for (int i = 0, b; i < Q; i++) {
    cin >> b;
    press[b] = press[b] ^ 1;
  }
  // Apply presses.
  for (int i = 1; i <= N; i++) {
    if (press[i]) {
      for (int j = i; j <= N; j += i) {
        white[j] = white[j] ^ 1;
      }
    }
  }
  // Convert to black greedily.
  int num_presses = 0;
  for (int i = 1; i <= N; i++) {
    if (white[i]) {
      num_presses++;
      for (int j = i; j <= N; j += i) {
        white[j] = white[j] ^ 1;
      }
    }
  }
  return num_presses;
}

int main() {
  int T;
  cin >> T;
  for (int t = 1; t <= T; t++) {
    cout << "Case #" << t << ": " << solve() << endl;
  }
  return 0;
}