-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1734C.cpp
More file actions
78 lines (69 loc) · 1.46 KB
/
Copy path1734C.cpp
File metadata and controls
78 lines (69 loc) · 1.46 KB
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define vs vector<string>
#define umapii unordered_map<int, int>
#define vpi vector<pair<int, int>>
#define endl '\n'
#define pb push_back
#define all(x) x.begin(), x.end()
#define yes cout << "YES\n";
#define no cout << "NO\n";
constexpr int INF = 1e9;
constexpr ll INFLL = 1e18;
constexpr int MOD = 1e9 + 7;
// bool isPrime(ll n) {
// if (n < 2) return false;
// if (n < 4) return true;
// if (n % 2 == 0 || n % 3 == 0) return false;
// for (ll i = 5; i * i <= n; i += 6) {
// if (n % i == 0 || n % (i + 2) == 0) return false;
// }
// return true;
// }
// ll gcd(ll a, ll b) {
// return b == 0 ? a : gcd(b, a % b);
// }
// ll lcm(ll a, ll b) {
// return (a / gcd(a, b)) * b;
// }
/*
*/
void solve()
{
ll n;
string s;
cin >> n >> s;
ll cost = 0;
vector<bool> vis(n, false);
for (int i = 0; i < n; i++)
{
ll idx = i;
while (idx < n && (s[idx] == '0' || vis[idx]))
{
if (vis[idx])
{
idx += (i + 1);
continue;
}
cost += (i + 1);
vis[idx] = true;
idx += (i + 1);
}
}
cout << cost << endl;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
ll tt = 1;
cin >> tt;
while (tt--)
{
solve();
}
return 0;
}