MCPcopy Create free account
hub / github.com/Vishruth-S/CompetitiveCode / main

Function main

CodeChef_problems/Minimum Insertions/solution.cpp:12–69  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

10int ans[200010];
11
12int32_t main() {
13 int t;
14 cin >> t;
15
16 while (t--) {
17 int n;
18 cin >> n;
19
20 int prev = 1;
21 vector <int> v;
22 vector <int> v1;
23
24 for (int i = 0; i < n; i++) {
25 int x;
26 cin >> x;
27
28 v1.push_back(x);
29
30 if (__gcd(prev, x) > 1) {
31 int top = v.back();
32 v.pop_back();
33 v.push_back(top + 1);
34 } else {
35 v.push_back(1);
36 }
37
38 prev = x;
39 }
40
41 if (__gcd(v1[0], v1.back()) > 1 && v.size() == 1) {
42 for (int i = 2; i <= n; i++) {
43 cout << n / (i - 1) + (n % (i - 1) != 0) << " ";
44 }
45 cout << endl;
46 continue;
47 }
48
49 if (__gcd(v1[0], v1.back()) > 1) {
50 v[0] += v.back();
51 v.pop_back();
52 }
53
54 for (int i = 2; i <= n; i++) {
55 ans[i] = 0;
56 }
57
58 for (int i : v) {
59 for (int j = 2; j <= i; j++) {
60 ans[j] += (i - 1) / (j - 1);
61 }
62 }
63
64 for (int i = 2; i <= n; i++) {
65 cout << ans[i] << " ";
66 }
67 cout << endl;
68 }
69}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected